关于 ButtonField
我想在点击ButtonField后 Label1 显示被点击行的DataKeyNames= "NetBizerID "值
怎么写?
ASPX 文件
<asp:GridView ID= "GridView1 " runat= "server " DataSourceID= "ObjectDataSource1 " OnRowCommand= "MyCommand " DataKeyNames= "NetBizerID ">
<Columns>
<asp:ButtonField CommandName= "DisplayID " Text= "按钮 " />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID= "ObjectDataSource1 " runat= "server " SelectMethod= "GetAllNetBizers "
TypeName= "LogicLayer.NetBizer "> </asp:ObjectDataSource>
<asp:Label ID= "Label1 " runat= "server "> </asp:Label>
CS 文件
public partial class test1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void MyCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName = "DisplayID ")
{
//
}
}
}
------解决方案--------------------if (e.CommandName == "DisplayID ")
{
Response.Write(this.GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)].Value);
}