需要选择线上单号后,再弹框选择明细。问题是我勾选的checkbox的checked值一直都是false。
在!IsPostBack绑定数据时,是能选择到checkbox的值。但是更新数据再绑定后就选择不了。
这个是什么原因,有什么方法可以解决这个问题
<%@ Register src="OrderGoods.ascx" tagname="myuc4" tagprefix="uc4" %>
<div id="divOrderGoods" runat="server" Visible="false" style="position:absolute; top: 200px; left: 100px;">
<uc4:myuc4 id="myuc4" runat="server" />
</div>
if (!IsPostBack) {
GridViewBind("");
}
GridViewBind("");
你没有贴代码,不知道是什么原因
后台: Dictionary lstStr = new Dictionary();
lstStr.Add("name", 2);
lstStr.Add("name1", 21);
lstStr.Add("name2", 22);
lstStr.Add("name3", 23);
GridView1.DataSource = lstStr;
GridView1.DataBind();
取值
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
System.Web.UI.HtmlControls.HtmlInputCheckBox a = GridView1.Rows[i].FindControl("cb") as System.Web.UI.HtmlControls.HtmlInputCheckBox;
Response.Write(string.Format("第{0}个,{1}<br/>", i, a.Checked));
}
}
结果

额,错了,
前台是这样的
后台绑定的时候,一定要在ispostback中绑定