GridView获取ID [英] GridView getting ID
本文介绍了GridView获取ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的网站基于在线购物
我的GridView与sqlDataSource连接,具有表名称ITEMTYPE(具有子项目列表)
此网格视图显示了CATEGORY....
代码:::
< asp:GridView ID =" span> runat =" 服务器" AutoGenerateColumns 错误" DataSourceID ="
宽度 =" 311px" GridLines 无" < 列 >
< asp:TemplateField >
< ItemTemplate >
< asp:LinkButton ID =" runat 服务器" 文本 <%#Eval(" ) OnClick ="
CssClass =" >> < /asp:LinkButton >
< /ItemTemplate >
< /asp:TemplateField >
< /列 >
< /asp:GridView >
我想获取相应的ID并将其存储在会话n中,并将其传递到新页面
解决方案
这些 链接 肯定 肯定 帮助 您: "http: msdn.microsoft.com/en -us/library/aa581796.aspx">链接1 "http: msdn.microsoft.com/en -us/library/aa479344.aspx>链接2
使用DeleteCommand并将数据键名称设置为Id
&更改命令名称,以显示详细信息或根据您的选择.
受保护的void GridView1_RowDeleting(对象发送者,GridViewDeleteEventArgs e)
{
字符串str = GridView2.DataKeys [e.RowIndex] .Value.ToString();
会话["ID"] = str;
或者您可以在querystring
中使用它 如
Response.Redirect("abc.aspx?+ str");
}
您可以使用GridView RowCommand
事件
检查此样本
GridView.RowCommand事件 [<asp:GridView ID="GridViewCategory" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSourceCat" Width="311px" GridLines="None"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("itemType") %>' OnClick="LinkButton1_Click" CssClass="decoration"></asp:LinkButton> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
I want to get corresponding ID and stored it session n pass it to new page
which show list of product corresponding to that id..解决方案these links will surely help You: "http://msdn.microsoft.com/en-us/library/aa581796.aspx">Link 1 "http://msdn.microsoft.com/en-us/library/aa479344.aspx">Link 2
Use DeleteCommand And set Datakeys name as Id
& Change The name of command as show details or as per ur choice.
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string str = GridView2.DataKeys[e.RowIndex].Value.ToString();
Session["ID"]=str;
or u can use it in querystring
as
Response.Redirect("abc.aspx?+str");
}
you can useGridView RowCommand
event
check this sample
GridView.RowCommand Event[^]
这篇关于GridView获取ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文