CheckBox 第二次选中提交不了
CheckBox 选中后提交第一次的时候系统能够正确处理(例如:待命 下岗) 返回主页面后 再选中CheckBox 点击 待命 或下岗按钮就不执行相应操作 应该是勾选了 但是CheckBox还不是选中的 怎样 修改呢 请高手指点下
[解决办法]
楼主是要还原上一次选择的状态??那你要保存数据起来才行了,然后读取数据匹配当前的项,匹配设置checked
[解决办法]
后台没有CheckBox的事件,不用加AutoPostBack="true" ,这个完全没有必要。
另外,不是你说的那样的,下面是一个例子直接拷贝粘贴测试
<%@ Page Language="C#" EnableViewState="true" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
public System.Data.DataTable GetData()
{
System.Data.DataTable dataTable1 = new System.Data.DataTable("BlogUser");
dataTable1.Columns.Add(new System.Data.DataColumn("UserId", typeof(System.Int32)));
dataTable1.Columns.Add(new System.Data.DataColumn("Title", typeof(System.String)));
for (int i = 0; i < 8; i++)
{
dataTable1.Rows.Add(i, "测试" + i.ToString());
}
return dataTable1;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridViewBind();
}
}
protected void GridViewCar_RowDataBound(object sender, GridViewRowEventArgs e)
{
}
// 待命
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
//currentRow.Cells[3].Text = SateToPicPerson(p.State);
//得到所选中的
foreach (GridViewRow row in GridViewCar.Rows)
{
CheckBox chkSelect = row.FindControl("chkSelect") as CheckBox;
if (chkSelect.Checked)
{
Response.Write("<li>选中的 userId = " + GridViewCar.DataKeys[row.RowIndex].Value.ToString());
}
}
GridViewBind();
}
// 下岗
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
//得到所选中的
foreach (GridViewRow row in GridViewCar.Rows)
{
CheckBox chkSelect = row.FindControl("chkSelect") as CheckBox;
if (chkSelect.Checked)
{
Response.Write("<li>选中的 userId = " + GridViewCar.DataKeys[row.RowIndex].Value.ToString());
}
}
GridViewBind();
}
protected void GridViewBind()
{
GridViewCar.DataSource = GetData();
GridViewCar.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridViewCar" runat="server" AutoGenerateColumns="False" Width="100%"
DataKeyNames="UserId" CssClass="bind_vichle" BackColor="White" Font-Size="0.8em"
OnRowDataBound="GridViewCar_RowDataBound">
<HeaderStyle HorizontalAlign="Center" Height="15px" BackColor="#2FA2E5" />
<RowStyle HorizontalAlign="Center" Height="14px" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserId" HeaderText="编号"></asp:BoundField>
<asp:BoundField DataField="Title" HeaderText="车牌号"></asp:BoundField>
<asp:BoundField HeaderText="类型"></asp:BoundField>
<asp:BoundField HeaderText="状态"></asp:BoundField>
</Columns>
</asp:GridView>
<asp:ImageButton ID="ImageButton1" runat="server" ToolTip="待命" ImageUrl="~/images/an_dm.gif"
OnClick="ImageButton1_Click" />
<asp:ImageButton ID="ImageButton2" runat="server" ToolTip="下岗" ImageUrl="~/images/an_xx.gif"
OnClick="ImageButton2_Click" />
</form>
</body>
</html>