这个问题有点棘手,但无论如何它在这里,所以我有一个有三列的gridview,其中两列是布尔复选框。我想要做的是当用户在编辑/更新模式下单击按钮时我想将两个框都设置为true或1.那么我该怎么做呢?帮助将不胜感激!!提前谢谢!
我在编辑模式下的代码示例:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="reservationid, bookid, EmployeeID"
DataSourceID="bookreservationDataSource">
<Columns>
<asp:CommandField ButtonType="Button" ShowEditButton="True"
ShowSelectButton="true"/>
<asp:BoundField DataField="booktitle" HeaderText="Title"
ReadOnly="true" SortExpression="booktitle" />
<asp:BoundField DataField="EmployeeID" HeaderText="Employee ID"
ReadOnly="true" SortExpression="EmployeeID" />
<asp:BoundField DataField="reservedate" HeaderText="Reserve date"
SortExpression="reservedate" />
<asp:CheckBoxField DataField="isapproved" HeaderText="Approved"
SortExpression="isapproved" />
<asp:CheckBoxField DataField="isdeleted" HeaderText="Deleted"
SortExpression="isdeleted" />
</Columns>
</asp:GridView>
我想在设置“编辑”之类的按钮时将两个复选框字段'isapproved'和'isdeleted'设置为true。
答案 0 :(得分:1)
你可以这样做......
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
((CheckBox)row.FindControl("FirstCheckBox")).Checked = true;
((CheckBox)row.FindControl("SecondCheckBox")).Checked = true;
GridView1.UpdateRow(row.RowIndex,true);
}
}