<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>
This is my Aspx code for the GridView
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;
}
and my code behind.
At the time of adding the row I have to check a paticular check box. I have been trying to check the checkbox by giving its values as true but it does not seem to work. Can someone tell me what I am doing wrong here?
CheckBoxto true orCheckBox.Checkedto true?OnRowDataBoundevent. Find the CheckBox, set itsCheckedvalue based on your algorithm.