protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
sqlcon = new SqlConnection(strCon);
string sqlstr = "update XSHD set XSHD_Subject='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',Time='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "',Place='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "',Organizer='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim() + "',Phone='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim() + "' XSHD_see'"
+ (RadioButtonList)(GridView1.Rows[e.RowIndex].FindControl("RadioButtonList1")).SelectedValue.ToString() + "' where XSHD_id='"
+ GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
sqlcom = new SqlCommand(sqlstr, sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
GridView1.EditIndex = -1;
GridViewBind();
}
{
sqlcon = new SqlConnection(strCon);
string sqlstr = "update XSHD set XSHD_Subject='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',Time='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "',Place='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "',Organizer='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim() + "',Phone='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim() + "' XSHD_see'"
+ (RadioButtonList)(GridView1.Rows[e.RowIndex].FindControl("RadioButtonList1")).SelectedValue.ToString() + "' where XSHD_id='"
+ GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
sqlcom = new SqlCommand(sqlstr, sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
GridView1.EditIndex = -1;
GridViewBind();
}
{
CheckBoxList cbl= (CheckBoxList )GridView1.Rows[i].FindControl("CheckBoxList ");
//绑定
}是CheckBox还是CheckBoxList?
<asp:ListItem Text="已" Value="0"></asp:ListItem>
<asp:ListItem Text="未" Value="1"></asp:ListItem>
</asp:DropDownList>可惜RadioButtonList好像不行啊,只能自己去写
或者用html控件name="rbtAudit" + DataKeys["id"] 根据主键来分组
{
sqlcon = new SqlConnection(strCon);
string sqlstr = "update XSHD set XSHD_Subject='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + "',Time='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim() + "',Place='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim() + "',Organizer='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim() + "',Phone='"
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim() + "',XSHD_see='"
+ ((DropDownList)(GridView1.Rows[e.RowIndex].FindControl("DropDownList1"))).SelectedValue + "' where XSHD_id='"
+ GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
sqlcom = new SqlCommand(sqlstr, sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
GridView1.EditIndex = -1;
GridViewBind();
}
在sql就处理好了:http://www.cnblogs.com/insus/articles/1944849.html
另外有关dropdownList相关的:
http://www.cnblogs.com/insus/articles/1997458.html
<asp:ListItem Text="已" Value="True"></asp:ListItem>
<asp:ListItem Text="未" Value="Flase"></asp:ListItem>
</asp:DropDownList>
你的这个代码我写在<EditItemTemplate>里了,就是GridView的编辑时显示的窗口。但是在非编辑时,我这“是否审核”列显示的是数据库中的True和False。这个问题怎么解决啊???
<asp:Label ID="Label1" runat="server" Text='<%# Eval("XSHD_see").Equals("True") ? "已审核" : "未审核" %>'></asp:Label>
改写成这样,结果运行时,“是否审核”列都显示的是 未审核
<asp:TemplateField HeaderText="是否审核" SortExpression="XSHD_see">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("XSHD_see").Equals("True") ? "已审核" : "未审核" %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="120px" Wrap="False" />
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("XSHD_see")%>' DataValueField="XSHD_see" DataTextField="XSHD_see">
<asp:ListItem Text="已审核" Value="True"></asp:ListItem>
<asp:ListItem Text="未审核" Value="False"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="是否审核" SortExpression="XSHD_see">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Convert.ToBoolean(Eval("XSHD_see")) ? "已审核" : "未审核"%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="120px" Wrap="False" />
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("XSHD_see")%>' DataValueField="XSHD_see" DataTextField="XSHD_see">
<asp:ListItem Text="已审核" Value="True"></asp:ListItem>
<asp:ListItem Text="未审核" Value="False"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
bit类型在Eval()里其实是装箱过的bool型