现在的位置: 首页 > 综合 > 正文

ASP.net GridView隐藏列

2012年09月28日 ⁄ 综合 ⁄ 共 678字 ⁄ 字号 评论关闭

前台,设置DataKeyNames:

   <asp:GridView ID="dg" runat="server" AutoGenerateColumns="False" AllowPaging="True"
            Width="100%" onrowdatabound="dg_RowDataBound" DataKeyNames ="EquipID,type">...

后台,获取数据:

   protected void dg_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
            {
                GridView dg = e.Row.Parent.Parent as GridView;
     
                string No = dg.DataKeys[e.Row.RowIndex].Values[0].ToString ();
                string type = dg.DataKeys[e.Row.RowIndex].Values[1].ToString ();
               }

            }

}

 

抱歉!评论已关闭.