<asp:GridView ID="SearchGrid" runat="server" GridLines="Both" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Q" HeaderText="Q" />
<asp:TemplateField HeaderText="C">
<ItemTemplate>
<asp:CheckBox ID="CCheckbox" runat="server" AutoPostBack="true" OnCheckedChanged="CCheckbox_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="R">
<ItemTemplate>
<asp:CheckBox ID="RCheckbox" runat="server" AutoPostBack="true" OnCheckedChanged="RCheckbox_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="E">
<ItemTemplate>
<asp:CheckBox ID="ECheckbox" runat="server" AutoPostBack="true" OnCheckedChanged="ECheckbox_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
这是我的 GridView 的 Aspx 代码
if (ViewState["SearchGrid"] == null)
{
SearchTable.Columns.Add(new DataColumn("Q", typeof(string)));
SearchTable.Columns.Add(new DataColumn("C", typeof(bool)));
SearchTable.Columns.Add(new DataColumn("R", typeof(bool)));
SearchTable.Columns.Add(new DataColumn("E", typeof(bool)));
ViewState["SearchGrid"] = SearchTable;
}
SearchTable =(DataTable) ViewState["SearchGrid"];
DataRow dr = null;
dr = SearchTable.NewRow();
dr["Q"] = MySearchTextBox.Text;
switch (SearchType)
{
case "Contains": dr["C"] =true;
break;
case "Related": dr["R"] = true;
break;
case "Exact": dr["E"] = true;
break;
}
和我后面的代码。
在添加行时,我必须选中一个特定的复选框。我一直试图通过将其值设为 true 来检查复选框,但它似乎不起作用。有人可以告诉我我在这里做错了什么吗?