Gridview 中的 CommandArgument [英] CommandArgument in the Gridview
本文介绍了Gridview 中的 CommandArgument的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的网格视图.
I have a gridview like this.
<asp:GridView ID="grdMerchant" runat="server" GridLines="None"
HeaderStyle-Font-Bold="True" AutoGenerateColumns="False" AllowSorting="True" ShowHeader="false" OnRowDataBound="grdMerchant_RowDataBound" OnRowCommand="grdMerchant_RowCommand" DataKeyNames="OrderID" style="table-layout:auto;width:100%;" >
<asp:TemplateField >
<ItemTemplate>
<asp:Linkbutton ID= "btnView" runat="server" Text="View" OnClick="btnView_OnClick" CommandArgument='<%#Eval("OrderID")%>' ></asp:Linkbutton>
如何获取所选行的 OrderID.我尝试使用
How do i have to get the OrderID of the selected row. I tried using
int OrderID = (int)grdMerchant.DataKeys[row.RowIndex][2];
但它为空,我知道这不是方法.帮我.
But it gets null and i know this is not the way. Help me.
先谢谢你!
推荐答案
试试这个
<asp:GridView ID="grd1" runat="Server" width="500px" AutoGenerateColumns="false" DataKeyNames="StateID" OnRowEditing="grd1_RowEditing">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnDelete" runat="server" CommandArgument='<%#Eval("StateID")%>' OnCommand="lnkDelete" Text="Delete">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
protected void lnkDelete(Object sender, CommandEventArgs e)
{
int iStID=int32.Parse(e.CommandArgument.ToString());
}
//iStID has the DataKey value which you can use.
这篇关于Gridview 中的 CommandArgument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文