TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ajay s
NA
1
1.2k
asp.net
Jul 25 2014 7:03 AM
In asp.net iam using gridview for attendance purpose .in this iam using checkbox and radiobutton in one item template(one cell) but i have control for only radio button . when i click add new row button checkbox it became unchecked . this is bcoz it takes only one field for a column .
aspx.page
<asp:GridView ID="GridView1" runat="server" ShowFooter="True" AutoGenerateColumns="False"
style="position:absolute; top: 136px; left: 20px; width: 488px; margin-bottom: 0px; height: 421px;" onrowdatabound="GridView1_RowDataBound"
>
<Columns>
<asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
<asp:TemplateField HeaderText = "Employee_id" SortExpression = "Employee_id">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" Height="18px" Width="120px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Name" SortExpression = "Name" >
<ItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" Height="18px" Width="120px" >
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Grade" SortExpression ="Grade">
<ItemTemplate>
<asp:DropDownList ID="ddgrade" runat="server" Height="18px" Width="120px" >
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="1" >
<ItemTemplate>
<asp:CheckBox ID="cb1" runat="server" />
<asp:RadioButton ID="Rb1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="2" >
<ItemTemplate>
<asp:CheckBox ID="cb2" runat="server" />
<asp:RadioButton ID="Rb2" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="3" >
<ItemTemplate>
<asp:CheckBox ID="cb3" runat="server" />
<asp:RadioButton ID="Rb3" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="4" >
<ItemTemplate>
<asp:CheckBox ID="cb4" runat="server" />
<asp:RadioButton ID="Rb4" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="5" SortExpression="5">
<ItemTemplate>
<asp:CheckBox ID="cb5" runat="server" />
<asp:RadioButton ID="Rb5" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="6" SortExpression="6" >
<ItemTemplate>
<asp:CheckBox ID="cb6" runat="server" />
<asp:RadioButton ID="Rb6" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="7" SortExpression="7" >
<ItemTemplate>
<asp:CheckBox ID="cb7" runat="server" />
<asp:RadioButton ID="Rb7" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="8" SortExpression="8" >
<ItemTemplate>
<asp:CheckBox ID="cb8" runat="server" />
<asp:RadioButton ID="Rb8" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="9" SortExpression="9" >
<ItemTemplate>
<asp:CheckBox ID="cb9" runat="server" />
<asp:RadioButton ID="Rb9" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="10" SortExpression="10">
<ItemTemplate>
<asp:CheckBox ID="cb10" runat="server" />
<asp:RadioButton ID="Rb10" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="11" SortExpression="11" >
<ItemTemplate>
<asp:CheckBox ID="cb11" runat="server" />
<asp:RadioButton ID="Rb11" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="12" SortExpression="12" >
<ItemTemplate>
<asp:CheckBox ID="cb12" runat="server" />
<asp:RadioButton ID="Rb12" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="13" SortExpression="13">
<ItemTemplate>
<asp:CheckBox ID="cb13" runat="server" />
<asp:RadioButton ID="Rb13" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="14" SortExpression="14" >
<ItemTemplate>
<asp:CheckBox ID="cb14" runat="server" />
<asp:RadioButton ID="Rb14" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="15" SortExpression="15">
<ItemTemplate>
<asp:CheckBox ID="cb15" runat="server" />
<asp:RadioButton ID="Rb15" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="16" SortExpression="1" >
<ItemTemplate>
<asp:CheckBox ID="cb16" runat="server" />
<asp:RadioButton ID="Rb16" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="17" SortExpression="2" >
<ItemTemplate>
<asp:CheckBox ID="cb17" runat="server" />
<asp:RadioButton ID="Rb17" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="18" SortExpression="3">
<ItemTemplate>
<asp:CheckBox ID="cb18" runat="server" />
<asp:RadioButton ID="Rb18" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="19" SortExpression="4" >
<ItemTemplate>
<asp:CheckBox ID="cb19" runat="server" />
<asp:RadioButton ID="Rb19" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="20" SortExpression="5">
<ItemTemplate>
<asp:CheckBox ID="cb20" runat="server" />
<asp:RadioButton ID="Rb20" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="21" SortExpression="6" >
<ItemTemplate>
<asp:CheckBox ID="cb21" runat="server" />
<asp:RadioButton ID="Rb21" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="22" SortExpression="7" >
<ItemTemplate>
<asp:CheckBox ID="cb22" runat="server" />
<asp:RadioButton ID="Rb22" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="23" SortExpression="8" >
<ItemTemplate>
<asp:CheckBox ID="cb23" runat="server" />
<asp:RadioButton ID="Rb23" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="24" SortExpression="9" >
<ItemTemplate>
<asp:CheckBox ID="cb24" runat="server" />
<asp:RadioButton ID="Rb24" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="25" SortExpression="10" >
<ItemTemplate>
<asp:CheckBox ID="cb25" runat="server" />
<asp:RadioButton ID="Rb25" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="26" SortExpression="11" >
<ItemTemplate>
<asp:CheckBox ID="cb26" runat="server" />
<asp:RadioButton ID="Rb26" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="27" SortExpression="12">
<ItemTemplate>
<asp:CheckBox ID="cb27" runat="server" />
<asp:RadioButton ID="Rb27" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="28" SortExpression="13" >
<ItemTemplate>
<asp:CheckBox ID="cb28" runat="server" />
<asp:RadioButton ID="Rb28" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="29" SortExpression="14" >
<ItemTemplate>
<asp:CheckBox ID="cb29" runat="server"/>
<asp:RadioButton ID="Rb29" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="30" SortExpression="15">
<ItemTemplate>
<asp:CheckBox ID="cb30" runat="server" />
<asp:RadioButton ID="Rb30" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="31" SortExpression="15" >
<ItemTemplate>
<asp:CheckBox ID="cb31" runat="server" />
<asp:RadioButton ID="Rb31" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="NoOfDays" SortExpression="NoOfDays">
<ItemTemplate>
<asp:TextBox ID="txtnoofdays" runat="server"></asp:TextBox>
<asp:TextBox ID="txttot" runat="server"></asp:TextBox>
<asp:TextBox ID="txttotal" runat="server"></asp:TextBox>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<FooterTemplate>
<asp:Button ID="ButtonAdd" runat="server"
Text="Add New Row"
onclick="ButtonAdd_Click" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" Horizontal />
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
</asp:GridView>
default.aspx.cs
private void select()
{
foreach (GridViewRow GRV in GridView1.Rows)
{
DropDownList ddl1 = (DropDownList)GRV.Cells[0].FindControl("DropDownList1");
DropDownList ddl2 = (DropDownList)GRV.Cells[0].FindControl("DropDownList2");
DropDownList dgra = (DropDownList)GRV.Cells[0].FindControl("ddgrade");
con.Open();
SqlCommand cmd = new SqlCommand(" select Employee_id from employee", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
da.Fill(ds);
ddl1.DataSource = ds;
ddl1.DataValueField = "Employee_id";
ddl1.DataTextField = "Employee_id";
ddl1.DataBind();
ddl1.Items.Insert(0, new ListItem("Please Select", "Emp_id"));
cmd.ExecuteNonQuery();
con.Close();
con.Open();
SqlDataReader dr;
SqlCommand cmd3 = new SqlCommand("select Distinct grade_SO,grade_Aso,grade_G,grade_LG,grade_FG,grade_other1,Grade_other2 from client_info", con);
dr = cmd3.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
dgra.Items.Add(new ListItem(dr[0].ToString()));
dgra.Items.Add(new ListItem(dr[1].ToString()));
dgra.Items.Add(new ListItem(dr[2].ToString()));
dgra.Items.Add(new ListItem(dr[3].ToString()));
dgra.Items.Add(new ListItem(dr[4].ToString()));
dgra.Items.Add(new ListItem(dr[5].ToString()));
dgra.Items.Add(new ListItem(dr[6].ToString()));
dgra.Items.Insert(0, new ListItem("Please Select", "grade"));
}
}
dr.Close();
con.Close();
con.Open();
SqlCommand cmd1 = new SqlCommand(" select Name from employee", con);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataSet ds1 = new DataSet();
DataTable dt1 = new DataTable();
da1.Fill(ds1);
ddl2.DataSource = ds1;
ddl2.DataValueField = "Name";
ddl2.DataTextField = "Name";
ddl2.DataBind();
ddl2.Items.Insert(0, new ListItem("Please Select", "Name"));
cmd1.ExecuteNonQuery();
con.Close();
}
}
private void SetInitialRow()
{
DataTable dt = new DataTable();
DataRow dr = null;
dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
dt.Columns.Add(new DataColumn("Column1", typeof(string)));
dt.Columns.Add(new DataColumn("Column2", typeof(string)));
dt.Columns.Add(new DataColumn("Column3", typeof(string)));
dt.Columns.Add(new DataColumn("Column4", typeof(string)));
dt.Columns.Add(new DataColumn("Column5", typeof(string)));
dt.Columns.Add(new DataColumn("Column6", typeof(string)));
dt.Columns.Add(new DataColumn("Column7", typeof(string)));
dt.Columns.Add(new DataColumn("Column8", typeof(string)));
dt.Columns.Add(new DataColumn("Column9", typeof(string)));
dt.Columns.Add(new DataColumn("Column10", typeof(string)));
dt.Columns.Add(new DataColumn("Column11", typeof(string)));
dt.Columns.Add(new DataColumn("Column12", typeof(string)));
dt.Columns.Add(new DataColumn("Column13", typeof(string)));
dt.Columns.Add(new DataColumn("Column14", typeof(string)));
dt.Columns.Add(new DataColumn("Column15", typeof(string)));
dt.Columns.Add(new DataColumn("Column16", typeof(string)));
dt.Columns.Add(new DataColumn("Column17", typeof(string)));
dt.Columns.Add(new DataColumn("Column18", typeof(string)));
dt.Columns.Add(new DataColumn("Column19", typeof(string)));
dt.Columns.Add(new DataColumn("Column20", typeof(string)));
dt.Columns.Add(new DataColumn("Column21", typeof(string)));
dt.Columns.Add(new DataColumn("Column22", typeof(string)));
dt.Columns.Add(new DataColumn("Column23", typeof(string)));
dt.Columns.Add(new DataColumn("Column24", typeof(string)));
dt.Columns.Add(new DataColumn("Column25", typeof(string)));
dt.Columns.Add(new DataColumn("Column26", typeof(string)));
dt.Columns.Add(new DataColumn("Column27", typeof(string)));
dt.Columns.Add(new DataColumn("Column28", typeof(string)));
dt.Columns.Add(new DataColumn("Column29", typeof(string)));
dt.Columns.Add(new DataColumn("Column30", typeof(string)));
dt.Columns.Add(new DataColumn("Column31", typeof(string)));
dt.Columns.Add(new DataColumn("Column32", typeof(string)));
dt.Columns.Add(new DataColumn("Column33", typeof(string)));
dt.Columns.Add(new DataColumn("Column34", typeof(string)));
dt.Columns.Add(new DataColumn("Column35", typeof(string)));
dr = dt.NewRow();
dr["RowNumber"] = 1;
dr["Column1"] = string.Empty;
dr["Column2"] = string.Empty;
dt.Rows.Add(dr);
//Store the DataTable in ViewState for future reference
ViewState["CurrentTable"] = dt;
//Bind the Gridview
GridView1.DataSource = dt;
GridView1.DataBind();
//After binding the gridview, we can then extract and fill the DropDownList with Data
DropDownList ddl1 = (DropDownList)GridView1.Rows[0].Cells[1].FindControl("DropDownList1");
DropDownList ddl2 = (DropDownList)GridView1.Rows[0].Cells[2].FindControl("DropDownList2");
DropDownList dgra = (DropDownList)GridView1.Rows[0].Cells[2].FindControl("ddgrade");
// dd();
}
private void AddNewRowToGrid()
{
if (ViewState["CurrentTable"] != null)
{
DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
DataRow drCurrentRow = null;
if (dtCurrentTable.Rows.Count > 0)
{
drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow["RowNumber"] = dtCurrentTable.Rows.Count + 1;
//add new row to DataTable
dtCurrentTable.Rows.Add(drCurrentRow);
//Store the current data to ViewState for future reference
ViewState["CurrentTable"] = dtCurrentTable;
// dd();
for (int i = 0; i < dtCurrentTable.Rows.Count - 1; i++)
{
DropDownList ddl1 = (DropDownList)GridView1.Rows[i].Cells[1].FindControl("DropDownList1");
DropDownList ddl2 = (DropDownList)GridView1.Rows[i].Cells[2].FindControl("DropDownList2");
DropDownList ddl3 = (DropDownList)GridView1.Rows[i].Cells[3].FindControl("ddgrade");
// Update the DataRow with the DDL Selected Items
dtCurrentTable.Rows[i]["Column1"] = ddl1.SelectedItem.Text;
dtCurrentTable.Rows[i]["Column2"] = ddl2.SelectedItem.Text;
dtCurrentTable.Rows[i]["Column3"] = ddl3.SelectedItem.Text;
//extract the TextBox values
TextBox box1 = (TextBox)GridView1.Rows[i].Cells[35].FindControl("txtnoofdays");
TextBox box2 = (TextBox)GridView1.Rows[i].Cells[35].FindControl("txttot");
TextBox box3 = (TextBox)GridView1.Rows[i].Cells[35].FindControl("txttotal");
dtCurrentTable.Rows[i]["Column35"] = box1.Text;
dtCurrentTable.Rows[i]["Column35"] = box2.Text;
dtCurrentTable.Rows[i]["Column35"] = box3.Text;
//// dtCurrentTable.Rows[i]["Column3"] = ddl3.SelectedItem.Text;
//extract the checkbox
CheckBox c = (CheckBox)GridView1.Rows[i].Cells[4].FindControl("cb1");
RadioButton r = (RadioButton)GridView1.Rows[i].Cells[4].FindControl("Rb1");
dtCurrentTable.Rows[i]["Column4"] = c.Checked;
dtCurrentTable.Rows[i]["Column4"] = r.Checked;
CheckBox c1 = (CheckBox)GridView1.Rows[i].Cells[5].FindControl("cb2");
RadioButton r1 = (RadioButton)GridView1.Rows[i].Cells[5].FindControl("Rb2");
dtCurrentTable.Rows[i]["Column5"] = c1.Checked;
dtCurrentTable.Rows[i]["Column5"] = r1.Checked;
CheckBox c2 = (CheckBox)GridView1.Rows[i].Cells[6].FindControl("cb3");
RadioButton r2 = (RadioButton)GridView1.Rows[i].Cells[6].FindControl("Rb3");
dtCurrentTable.Rows[i]["Column6"] = c2.Checked;
dtCurrentTable.Rows[i]["Column6"] = r2.Checked;
CheckBox c3 = (CheckBox)GridView1.Rows[i].Cells[7].FindControl("cb4");
RadioButton r3 = (RadioButton)GridView1.Rows[i].Cells[7].FindControl("Rb4");
dtCurrentTable.Rows[i]["Column7"] = c3.Checked;
dtCurrentTable.Rows[i]["Column7"] = r3.Checked;
CheckBox c4 = (CheckBox)GridView1.Rows[i].Cells[8].FindControl("cb5");
RadioButton r4 = (RadioButton)GridView1.Rows[i].Cells[8].FindControl("Rb5");
dtCurrentTable.Rows[i]["Column8"] = c4.Checked;
dtCurrentTable.Rows[i]["Column8"] = r4.Checked;
CheckBox c5 = (CheckBox)GridView1.Rows[i].Cells[9].FindControl("cb6");
RadioButton r5 = (RadioButton)GridView1.Rows[i].Cells[9].FindControl("Rb6");
dtCurrentTable.Rows[i]["Column9"] = c5.Checked;
dtCurrentTable.Rows[i]["Column9"] = r5.Checked;
CheckBox c6 = (CheckBox)GridView1.Rows[i].Cells[10].FindControl("cb7");
RadioButton r6 = (RadioButton)GridView1.Rows[i].Cells[10].FindControl("Rb7");
dtCurrentTable.Rows[i]["Column10"] = c6.Checked;
dtCurrentTable.Rows[i]["Column10"] = r6.Checked;
CheckBox c7 = (CheckBox)GridView1.Rows[i].Cells[11].FindControl("cb8");
RadioButton r7 = (RadioButton)GridView1.Rows[i].Cells[11].FindControl("Rb8");
dtCurrentTable.Rows[i]["Column11"] = c7.Checked;
dtCurrentTable.Rows[i]["Column11"] = r7.Checked;
CheckBox c8 = (CheckBox)GridView1.Rows[i].Cells[12].FindControl("cb9");
RadioButton r8 = (RadioButton)GridView1.Rows[i].Cells[12].FindControl("Rb9");
dtCurrentTable.Rows[i]["Column12"] = c8.Checked;
dtCurrentTable.Rows[i]["Column12"] = r8.Checked;
CheckBox c9 = (CheckBox)GridView1.Rows[i].Cells[13].FindControl("cb10");
RadioButton r9 = (RadioButton)GridView1.Rows[i].Cells[13].FindControl("Rb10");
dtCurrentTable.Rows[i]["Column13"] = c9.Checked;
dtCurrentTable.Rows[i]["Column13"] = r9.Checked;
CheckBox c10 = (CheckBox)GridView1.Rows[i].Cells[14].FindControl("cb11");
RadioButton r10 = (RadioButton)GridView1.Rows[i].Cells[14].FindControl("Rb11");
dtCurrentTable.Rows[i]["Column14"] = c10.Checked;
dtCurrentTable.Rows[i]["Column14"] = r10.Checked;
CheckBox c11 = (CheckBox)GridView1.Rows[i].Cells[15].FindControl("cb12");
RadioButton r11 = (RadioButton)GridView1.Rows[i].Cells[15].FindControl("Rb12");
dtCurrentTable.Rows[i]["Column15"] = c11.Checked;
dtCurrentTable.Rows[i]["Column15"] = r11.Checked;
CheckBox c12 = (CheckBox)GridView1.Rows[i].Cells[16].FindControl("cb13");
RadioButton r12 = (RadioButton)GridView1.Rows[i].Cells[16].FindControl("Rb13");
dtCurrentTable.Rows[i]["Column16"] = c12.Checked;
dtCurrentTable.Rows[i]["Column16"] = r12.Checked;
CheckBox c13 = (CheckBox)GridView1.Rows[i].Cells[17].FindControl("cb14");
RadioButton r13 = (RadioButton)GridView1.Rows[i].Cells[17].FindControl("Rb14");
dtCurrentTable.Rows[i]["Column17"] = c13.Checked;
dtCurrentTable.Rows[i]["Column17"] = r13.Checked;
CheckBox c14 = (CheckBox)GridView1.Rows[i].Cells[18].FindControl("cb15");
RadioButton r14 = (RadioButton)GridView1.Rows[i].Cells[18].FindControl("Rb15");
dtCurrentTable.Rows[i]["Column18"] = c14.Checked;
dtCurrentTable.Rows[i]["Column18"] = r14.Checked;
CheckBox c15 = (CheckBox)GridView1.Rows[i].Cells[19].FindControl("cb16");
RadioButton r15 = (RadioButton)GridView1.Rows[i].Cells[19].FindControl("Rb16");
dtCurrentTable.Rows[i]["Column19"] = c15.Checked;
dtCurrentTable.Rows[i]["Column19"] = r15.Checked;
CheckBox c16 = (CheckBox)GridView1.Rows[i].Cells[20].FindControl("cb17");
RadioButton r16 = (RadioButton)GridView1.Rows[i].Cells[20].FindControl("Rb17");
dtCurrentTable.Rows[i]["Column20"] = c16.Checked;
dtCurrentTable.Rows[i]["Column20"] = r16.Checked;
CheckBox c17 = (CheckBox)GridView1.Rows[i].Cells[21].FindControl("cb18");
RadioButton r17 = (RadioButton)GridView1.Rows[i].Cells[21].FindControl("Rb18");
dtCurrentTable.Rows[i]["Column21"] = c17.Checked;
dtCurrentTable.Rows[i]["Column21"] = r17.Checked;
CheckBox c18 = (CheckBox)GridView1.Rows[i].Cells[22].FindControl("cb19");
RadioButton r18 = (RadioButton)GridView1.Rows[i].Cells[22].FindControl("Rb19");
dtCurrentTable.Rows[i]["Column22"] = c18.Checked;
dtCurrentTable.Rows[i]["Column22"] = r18.Checked;
CheckBox c19 = (CheckBox)GridView1.Rows[i].Cells[23].FindControl("cb20");
RadioButton r19 = (RadioButton)GridView1.Rows[i].Cells[23].FindControl("Rb20");
dtCurrentTable.Rows[i]["Column23"] = c19.Checked;
dtCurrentTable.Rows[i]["Column23"] = r19.Checked;
CheckBox c20 = (CheckBox)GridView1.Rows[i].Cells[24].FindControl("cb21");
RadioButton r20 = (RadioButton)GridView1.Rows[i].Cells[24].FindControl("Rb21");
dtCurrentTable.Rows[i]["Column24"] = c20.Checked;
dtCurrentTable.Rows[i]["Column24"] = r20.Checked;
CheckBox c21 = (CheckBox)GridView1.Rows[i].Cells[25].FindControl("cb22");
RadioButton r21 = (RadioButton)GridView1.Rows[i].Cells[25].FindControl("Rb22");
dtCurrentTable.Rows[i]["Column25"] = c21.Checked;
dtCurrentTable.Rows[i]["Column25"] = r21.Checked;
CheckBox c22 = (CheckBox)GridView1.Rows[i].Cells[26].FindControl("cb23");
RadioButton r22 = (RadioButton)GridView1.Rows[i].Cells[26].FindControl("Rb23");
dtCurrentTable.Rows[i]["Column26"] = c22.Checked;
dtCurrentTable.Rows[i]["Column26"] = r22.Checked;
CheckBox c23 = (CheckBox)GridView1.Rows[i].Cells[27].FindControl("cb24");
RadioButton r23 = (RadioButton)GridView1.Rows[i].Cells[27].FindControl("Rb24");
dtCurrentTable.Rows[i]["Column27"] = c23.Checked;
dtCurrentTable.Rows[i]["Column27"] = r23.Checked;
CheckBox c24 = (CheckBox)GridView1.Rows[i].Cells[28].FindControl("cb25");
RadioButton r24 = (RadioButton)GridView1.Rows[i].Cells[28].FindControl("Rb25");
dtCurrentTable.Rows[i]["Column28"] = c24.Checked;
dtCurrentTable.Rows[i]["Column28"] = r24.Checked;
CheckBox c25 = (CheckBox)GridView1.Rows[i].Cells[29].FindControl("cb26");
RadioButton r25 = (RadioButton)GridView1.Rows[i].Cells[29].FindControl("Rb26");
dtCurrentTable.Rows[i]["Column29"] = c25.Checked;
dtCurrentTable.Rows[i]["Column29"] = r25.Checked;
CheckBox c26 = (CheckBox)GridView1.Rows[i].Cells[30].FindControl("cb27");
RadioButton r26 = (RadioButton)GridView1.Rows[i].Cells[30].FindControl("Rb27");
dtCurrentTable.Rows[i]["Column30"] = c26.Checked;
dtCurrentTable.Rows[i]["Column30"] = r26.Checked;
CheckBox c27 = (CheckBox)GridView1.Rows[i].Cells[31].FindControl("cb28");
RadioButton r27 = (RadioButton)GridView1.Rows[i].Cells[31].FindControl("Rb28");
dtCurrentTable.Rows[i]["Column31"] = c27.Checked;
dtCurrentTable.Rows[i]["Column31"] = r27.Checked;
CheckBox c28 = (CheckBox)GridView1.Rows[i].Cells[32].FindControl("cb29");
RadioButton r28 = (RadioButton)GridView1.Rows[i].Cells[32].FindControl("Rb29");
dtCurrentTable.Rows[i]["Column32"] = c28.Checked;
dtCurrentTable.Rows[i]["Column32"] = r28.Checked;
CheckBox c29 = (CheckBox)GridView1.Rows[i].Cells[33].FindControl("cb30");
RadioButton r29 = (RadioButton)GridView1.Rows[i].Cells[33].FindControl("Rb30");
dtCurrentTable.Rows[i]["Column33"] = c29.Checked;
dtCurrentTable.Rows[i]["Column33"] = r29.Checked;
CheckBox c30 = (CheckBox)GridView1.Rows[i].Cells[34].FindControl("cb31");
RadioButton r30 = (RadioButton)GridView1.Rows[i].Cells[34].FindControl("Rb31");
dtCurrentTable.Rows[i]["Column34"] = c30.Checked;
dtCurrentTable.Rows[i]["Column34"] = r30.Checked;
//extract the TextBox values
//extract the DropDownList Selected Items
}
//Rebind the Grid with the current data to reflect changes
GridView1.DataSource = dtCurrentTable;
GridView1.DataBind();
}
}
else
{
Response.Write("ViewState is null");
}
//Set Previous Data on Postbacks
SetPreviousData();
// dd();
}
private void SetPreviousData()
{
int rowIndex = 0;
if (ViewState["CurrentTable"] != null)
{
DataTable dt = (DataTable)ViewState["CurrentTable"];
if (dt.Rows.Count > 0)
{
select();
// dd();
for (int i = 0; i < dt.Rows.Count; i++)
{
TextBox box1 = (TextBox)GridView1.Rows[i].Cells[35].FindControl("txtnoofdays");
TextBox box2 = (TextBox)GridView1.Rows[i].Cells[35].FindControl("txttot");
TextBox box3 = (TextBox)GridView1.Rows[i].Cells[35].FindControl("txttotal");
DropDownList ddl1 = (DropDownList)GridView1.Rows[rowIndex].Cells[1].FindControl("DropDownList1");
DropDownList ddl2 = (DropDownList)GridView1.Rows[rowIndex].Cells[2].FindControl("DropDownList2");
DropDownList ddl3 = (DropDownList)GridView1.Rows[rowIndex].Cells[3].FindControl("ddgrade");
CheckBox c = (CheckBox)GridView1.Rows[i].Cells[4].FindControl("cb1");
RadioButton r = (RadioButton)GridView1.Rows[i].Cells[4].FindControl("Rb1");
CheckBox c1 = (CheckBox)GridView1.Rows[i].Cells[5].FindControl("cb2");
RadioButton r1 = (RadioButton)GridView1.Rows[i].Cells[5].FindControl("Rb2");
CheckBox c2 = (CheckBox)GridView1.Rows[i].Cells[6].FindControl("cb3");
RadioButton r2 = (RadioButton)GridView1.Rows[i].Cells[6].FindControl("Rb3");
CheckBox c3 = (CheckBox)GridView1.Rows[i].Cells[7].FindControl("cb4");
RadioButton r3 = (RadioButton)GridView1.Rows[i].Cells[7].FindControl("Rb4");
CheckBox c4 = (CheckBox)GridView1.Rows[i].Cells[8].FindControl("cb5");
RadioButton r4 = (RadioButton)GridView1.Rows[i].Cells[8].FindControl("Rb5");
CheckBox c5 = (CheckBox)GridView1.Rows[i].Cells[9].FindControl("cb6");
RadioButton r5 = (RadioButton)GridView1.Rows[i].Cells[9].FindControl("Rb6");
CheckBox c6 = (CheckBox)GridView1.Rows[i].Cells[10].FindControl("cb7");
RadioButton r6 = (RadioButton)GridView1.Rows[i].Cells[10].FindControl("Rb7");
CheckBox c7 = (CheckBox)GridView1.Rows[i].Cells[11].FindControl("cb8");
RadioButton r7 = (RadioButton)GridView1.Rows[i].Cells[11].FindControl("Rb8");
CheckBox c8 = (CheckBox)GridView1.Rows[i].Cells[12].FindControl("cb9");
RadioButton r8 = (RadioButton)GridView1.Rows[i].Cells[12].FindControl("Rb9");
CheckBox c9 = (CheckBox)GridView1.Rows[i].Cells[13].FindControl("cb10");
RadioButton r9 = (RadioButton)GridView1.Rows[i].Cells[13].FindControl("Rb10");
CheckBox c10 = (CheckBox)GridView1.Rows[i].Cells[14].FindControl("cb11");
RadioButton r10 = (RadioButton)GridView1.Rows[i].Cells[14].FindControl("Rb11");
CheckBox c11 = (CheckBox)GridView1.Rows[i].Cells[15].FindControl("cb12");
RadioButton r11 = (RadioButton)GridView1.Rows[i].Cells[15].FindControl("Rb12");
CheckBox c12 = (CheckBox)GridView1.Rows[i].Cells[16].FindControl("cb13");
RadioButton r12 = (RadioButton)GridView1.Rows[i].Cells[16].FindControl("Rb13");
CheckBox c13 = (CheckBox)GridView1.Rows[i].Cells[17].FindControl("cb14");
RadioButton r13 = (RadioButton)GridView1.Rows[i].Cells[17].FindControl("Rb14");
CheckBox c14 = (CheckBox)GridView1.Rows[i].Cells[18].FindControl("cb15");
RadioButton r14 = (RadioButton)GridView1.Rows[i].Cells[18].FindControl("Rb15");
CheckBox c15 = (CheckBox)GridView1.Rows[i].Cells[19].FindControl("cb16");
RadioButton r15 = (RadioButton)GridView1.Rows[i].Cells[19].FindControl("Rb16");
CheckBox c16 = (CheckBox)GridView1.Rows[i].Cells[20].FindControl("cb17");
RadioButton r16 = (RadioButton)GridView1.Rows[i].Cells[20].FindControl("Rb17");
CheckBox c17 = (CheckBox)GridView1.Rows[i].Cells[21].FindControl("cb18");
RadioButton r17 = (RadioButton)GridView1.Rows[i].Cells[21].FindControl("Rb18");
CheckBox c18 = (CheckBox)GridView1.Rows[i].Cells[22].FindControl("cb19");
RadioButton r18 = (RadioButton)GridView1.Rows[i].Cells[22].FindControl("Rb19");
CheckBox c19 = (CheckBox)GridView1.Rows[i].Cells[23].FindControl("cb20");
RadioButton r19 = (RadioButton)GridView1.Rows[i].Cells[23].FindControl("Rb20");
CheckBox c20 = (CheckBox)GridView1.Rows[i].Cells[24].FindControl("cb21");
RadioButton r20 = (RadioButton)GridView1.Rows[i].Cells[24].FindControl("Rb21");
CheckBox c21 = (CheckBox)GridView1.Rows[i].Cells[25].FindControl("cb22");
RadioButton r21 = (RadioButton)GridView1.Rows[i].Cells[25].FindControl("Rb22");
CheckBox c22 = (CheckBox)GridView1.Rows[i].Cells[26].FindControl("cb23");
RadioButton r22 = (RadioButton)GridView1.Rows[i].Cells[26].FindControl("Rb23");
CheckBox c23 = (CheckBox)GridView1.Rows[i].Cells[27].FindControl("cb24");
RadioButton r23 = (RadioButton)GridView1.Rows[i].Cells[27].FindControl("Rb24");
CheckBox c24 = (CheckBox)GridView1.Rows[i].Cells[28].FindControl("cb25");
RadioButton r24 = (RadioButton)GridView1.Rows[i].Cells[28].FindControl("Rb25");
CheckBox c25 = (CheckBox)GridView1.Rows[i].Cells[29].FindControl("cb26");
RadioButton r25 = (RadioButton)GridView1.Rows[i].Cells[29].FindControl("Rb26");
CheckBox c26 = (CheckBox)GridView1.Rows[i].Cells[30].FindControl("cb27");
RadioButton r26 = (RadioButton)GridView1.Rows[i].Cells[30].FindControl("Rb27");
CheckBox c27 = (CheckBox)GridView1.Rows[i].Cells[31].FindControl("cb28");
RadioButton r27 = (RadioButton)GridView1.Rows[i].Cells[31].FindControl("Rb28");
CheckBox c28 = (CheckBox)GridView1.Rows[i].Cells[32].FindControl("cb29");
RadioButton r28 = (RadioButton)GridView1.Rows[i].Cells[32].FindControl("Rb29");
CheckBox c29 = (CheckBox)GridView1.Rows[i].Cells[33].FindControl("cb30");
RadioButton r29 = (RadioButton)GridView1.Rows[i].Cells[33].FindControl("Rb30");
CheckBox c30 = (CheckBox)GridView1.Rows[i].Cells[34].FindControl("cb31");
RadioButton r30 = (RadioButton)GridView1.Rows[i].Cells[34].FindControl("Rb31");
// dd();
if (i < dt.Rows.Count - 1)
{
//Assign the value from DataTable to the TextBox
box1.Text = dt.Rows[i]["Column35"].ToString();
box2.Text = dt.Rows[i]["Column35"].ToString();
box3.Text = dt.Rows[i]["Column35"].ToString();
//Set the Previous Selected Items on Each DropDownList on Postbacks
ddl1.ClearSelection();
ddl1.Items.FindByText(dt.Rows[i]["Column1"].ToString()).Selected = true;
ddl2.ClearSelection();
ddl2.Items.FindByText(dt.Rows[i]["Column2"].ToString()).Selected = true;
ddl3.ClearSelection();
ddl3.Items.FindByText(dt.Rows[i]["Column3"].ToString()).Selected = true;
c.Checked = Convert.ToBoolean(dt.Rows[i]["Column4"].ToString());
r.Checked = Convert.ToBoolean(dt.Rows[i]["Column4"].ToString());
//c1.Checked = Convert.ToBoolean(dt.Rows[i]["Column5"].ToString());
//r1.Checked = Convert.ToBoolean(dt.Rows[i]["Column5"].ToString());
}
rowIndex++;
}
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SetInitialRow();
select();
}
}
protected void ButtonAdd_Click(object sender, EventArgs e)
{
AddNewRowToGrid();
}
}
Reply
Answers (
1
)
put checked row from one datagridview to another .
Compare Files in Two Directories using C# by reading XML