aspx code
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="TestButton" runat="server" OnClick="TestButton_Click"
Text="AddNewRow" />
</div>
<div>
<asp:GridView ID="MyGrid" runat="server" GridLines="Both"
AutoGenerateColumns="false" OnDataBound="MyGrid_DataBound"
EnableViewState="true">
<Columns>
<asp:BoundField DataField="Name" HeaderText="name" />
<asp:TemplateField HeaderText="CheckBox1">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" EnableViewState="true"
runat="server" AutoPostBack="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CheckBox2">
<ItemTemplate>
<asp:CheckBox ID="CheckBox2" runat="server"
EnableViewState="true" AutoPostBack="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CheckBox3">
<ItemTemplate>
<asp:CheckBox ID="CheckBox3" runat="server"
AutoPostBack="true" EnableViewState="true" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
Code behind
public DataTable Dt = new DataTable();
protected void Page_Load(object sender, EventArgs e) { }
protected void TestButton_Click(object sender, EventArgs e)
{
DataRow dr = null;
if(ViewState["T"]==null)
{
Dt.Columns.Add(new DataColumn("Name", typeof(string)));
Dt.Columns.Add(new DataColumn("CheckBox1", typeof(bool)));
Dt.Columns.Add(new DataColumn("CheckBox2", typeof(bool)));
Dt.Columns.Add(new DataColumn("CheckBox3", typeof(bool)));
ViewState["T"] = Dt;
}
Dt =(DataTable) ViewState["T"];
dr = Dt.NewRow();
dr["Name"] = "Sam";
dr["CheckBox1"] = true;
dr["CheckBox2"] = false;
dr["CheckBox3"] = false;
Dt.Rows.Add(dr);
SearchGrid.DataSource = Dt;
SearchGrid.DataBind();
}
protected void MyGrid_DataBound(object sender, EventArgs e)
{
(SearchGrid.Rows[SearchGrid.Rows.Count - 1].Cells[1].FindControl("CheckBox1")
as CheckBox).Checked = true;
}
}
when i click the the Addnew row button the result would be some thing like this

but when i click again

the first row check box gets uncheckd. i have enabled the view state for each checkbox but still it does not work. is tehre some thing i should do with the data table which i am binding?