当前位置: 代码迷 >> ASP.NET >> 关于 ButtonField解决思路
  详细解决方案

关于 ButtonField解决思路

热度:374   发布时间:2013-02-26 00:00:00.0
关于 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); }
  相关解决方案