bhadri

bhadri

  • NA
  • 7
  • 0

How to check which check box is ticked in Dynamic gridview

Aug 3 2014 12:14 AM

I have Datagrid in asp.net page with the below mentioned data

Device Name

Column 1

Column 2

iPad

Check Box

Check Box

iPhone

Check Box

Check Box

iStore

Check Box

Check Box

For Example: - Like this


Here Check box is – Check Box Control on each Cell

Here Device_Name,Column1 and Column2 are column names, under these columns we have check boxes on both the columns, Please can anybody help me how do I we get to know which all the check box's are TICKED.

Once it has been TICKED I want to assign checked value (just to identify which are been ticked) to array list from Grid view (for storing purpose, later I will pass this array list to next page).

Could you please someone help me one this

Please Note that: - while creating Gridview initially Check box will not be having any Id’s because those check boxes are dynamically generated.

This is my C# code for creating dynamic Check boxes in Gridview :-

protected void GrdOSInfo_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

for (int i = 1; i < 3; i++)

{

//foreach (GridView row in GridView1.Rows)

//{

CheckBox chk = new CheckBox();

chk.EnableViewState = true;

chk.Enabled = true;

chk.ID = "chkb"+i;

e.Row.Cells[i].Controls.Add(chk);

//}

}

}

}

This is my asp.net code

<asp:GridView ID="GrdOSInfo" runat="server" CssClass="grid_table"

onrowdatabound="GrdOSInfo_RowDataBound" BackColor="White" Width="200px"

BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical"

>

<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />

<HeaderStyle CssClass="grid_head_row" Font-Bold="true" ForeColor="White"

BackColor="#000084" />

<PagerStyle CssClass="paging" BackColor="#999999" ForeColor="Black"

HorizontalAlign="Center" />

<RowStyle CssClass="grid_even_row" BackColor="#EEEEEE" ForeColor="Black" />

<AlternatingRowStyle CssClass="grid_even_row" BackColor="#DCDCDC" />

<SelectedRowStyle CssClass="grid_head_row" BackColor="#008A8C" Font-Bold="True"

ForeColor="White" />

<SortedAscendingCellStyle BackColor="#F1F1F1" />

<SortedAscendingHeaderStyle BackColor="#0000A9" />

<SortedDescendingCellStyle BackColor="#CAC9C9" />

<SortedDescendingHeaderStyle BackColor="#000065" />

</asp:GridView>