I already made it! ^_^
this is my code
protected void addchk_modalpopup_save_Click(object sender, ImageClickEventArgs e)
{
CheckBox chk = (sender as CheckBox);
int x = 0;
DataTable dt = new DataTable();
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox chkRow = (row.Cells[0].FindControl("chkAll") as CheckBox);
if (chkRow.Checked)
{
GridView GridView2 = (GridView)row.FindControl("GridView2");
for (int i = 0; i < GridView2.Rows.Count; i++)
{
CheckBox cbx = (CheckBox)GridView2.Rows[i].FindControl("ck2");
if (cbx.Checked)
{
x++;
//string firstColumnValue = GridView1.Rows[i].Cells[0].Text;
}
}
foreach (GridViewRow row2 in GridView2.Rows)
{
if (row2.RowType == DataControlRowType.DataRow)
{
bool isChecked = row2.Cells[0].Controls.OfType<CheckBox>().FirstOrDefault().Checked;
if (isChecked == true)
{
string checklist = row.Cells[1].Text;
string activity = row2.Cells[1].Text;
connection();
amicassaCon.Open();
SqlCommand insert = new SqlCommand("INSERT INTO checklist_activity (contract_num,milestone,checklist,activity) VALUES('" + contract_no.Text + "','" + milestonedrpdwnlist.SelectedValue + "','" + checklist + "','" + activity + "')", amicassaCon);
SqlDataReader dr = insert.ExecuteReader();
dr.Close();
amicassaCon.Close();
}
}
}
}
}
}
}
this is my markup
<asp:GridView ID="GridView1" runat="server" RowStyle-VerticalAlign="Top" AutoGenerateColumns="False" CellPadding="4" OnRowDataBound="OnRowDataBound" DataKeyNames="checklist" Width="100%" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle VerticalAlign="Top" BackColor="White"></AlternatingRowStyle>
<Columns>
<asp:TemplateField ItemStyle-Width=".01px" ItemStyle-Height="1">
<ItemTemplate>
<asp:CheckBox ID="chkAll" AutoPostBack="true" OnCheckedChanged="OnCheckedChanged" runat="server" Font-Size="XX-Small" />
</ItemTemplate>
<ItemStyle Height="5px" Width="5px"/>
</asp:TemplateField>
<asp:BoundField DataField="checklist" HeaderText="Checklist" />
<asp:TemplateField HeaderText="Activity">
<ItemTemplate>
<asp:GridView ID="GridView2" RowStyle-VerticalAlign="Top" ShowHeader="false" RowStyle-HorizontalAlign="left" runat="server" Width="100%" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" >
<AlternatingRowStyle BackColor="White" HorizontalAlign="Left" VerticalAlign="Top" />
<Columns>
<asp:TemplateField ItemStyle-Width=".01px" ItemStyle-Height="1">
<ItemTemplate >
<asp:CheckBox ID="ck2" runat="server" Width="3px" Height="3px"/>
</ItemTemplate>
<ItemStyle Width="0px" />
</asp:TemplateField>
<asp:BoundField DataField="activity" ItemStyle-Width="90%">
<ItemStyle Width="90%" />
</asp:BoundField>
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" ForeColor="White" Font-Bold="True" />
<HeaderStyle BackColor="#015e46" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="White" HorizontalAlign="Center" BackColor="#666666" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" ForeColor="White" Font-Bold="True" />
<HeaderStyle BackColor="#015e46" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="White" HorizontalAlign="Center" BackColor="#666666" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>