此篇是修正http://www.cnblogs.com/insus/articles/1413740.html

修正的地方,就是利用GridView的DataKeyNames属性,替代HiddenField。如果你已经应用了以前的方法,你可以保留,再写一个方法重载。

View Code
<asp:GridView ID="GridView1" runat="server" DataKeyNames="xxx"

 

重构之后:

View Code
 string GetCheckBoxSelectValue(GridView gridView, string checkBoxId)
        {
            string strTempValue = string.Empty;
            foreach (GridViewRow gvr in gridView.Rows)
            {
                CheckBox cb = (CheckBox)gvr.FindControl(checkBoxId);
                if (cb.Checked)
                {
                    strTempValue = strTempValue + "," + gridView.DataKeys[gvr.RowIndex].Value.ToString();
                }
            }
            return strTempValue;
        }

 

相关文章:

  • 2022-03-06
  • 2022-02-08
  • 2022-12-23
  • 2021-07-17
  • 2022-03-01
  • 2021-07-31
  • 2021-10-17
  • 2022-12-23
猜你喜欢
  • 2021-10-09
  • 2022-12-23
  • 2021-08-19
  • 2022-03-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案