Hi Everyone,

I have a gridview

<asp:GridView ID="grid" runat="server" AutoGenerateColumns="false" DataKeyNames="Id"ShowHeaderWhenEmpty="true">

inside the gridview there is a column with checkbox and another label.

<asp:CheckBox runat="server" ID="Retrieve" />

<asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>


My question is how do i retrieve that particular row of data according to the Checkbox checked.

Like for exmaple, the gridview i check the checkbox which is in the row 3. How do i retrieve the row 3 data?

Everyone, Please help me.. i have been searching for days and found same thing on the net. Would you provide me with some guideline? I really need some guideline to assist me..

Your help is great appreciated.

If you have any enquire Please post below. i will answer as soon as possible.


Recommended Answers

All 7 Replies


to display the data you have selected in checkbox can be populate it in checkbox changed event as follows

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    //TextBox tb = ((Control)sender).NamingContainer.FindControl("TextBox2") as TextBox;
    CheckBox chk = ((Control)sender).NamingContainer.FindControl("CheckBox1") as CheckBox;

    string requiredtext = chk.Text;

Hi kamilacbe,

Thanks for your response. I put your code in my project. i couldn't display the result in a label. I placed a breakpoint at the CheckBox1_CheckedChanged() the code did not execute till the breakpoint.

The checkbox is inside the gridview, is it possible?



yup it is ..as you have done in your sample inside your item template tag..then pass the column which has to be populated as the text for that checkbox...then in your change event go for this c# part .

Do u want the snippet for design too

<asp:GridView ID="GridView1" runat="server" BackColor="White" 
            BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" 
                    <RowStyle BackColor="White" ForeColor="#003399" />
                            <ItemTemplate >
                                <asp:CheckBox ID="CheckBox1" runat="server" Font-Italic="True" Text ='<%#Eval("name")%>'
                                    oncheckedchanged="CheckBox1_CheckedChanged" AutoPostBack="True" />
                                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>  
                        <asp:CommandField ShowEditButton="True" />
                    <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
                    <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
                    <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
                    <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />

In the c# code uncomment the textbox and pass the value to textobject you can find the output in gridview textbox. or go for response .write...

Thanks for the reply. I have tried your code but unable to display the checkbox's text in the textbox2.text...

I have tried your code on another project that uses datasource to populate in the gridview and i am able to display the checkbox's text in the textbox2.text..
But i am not supposed to use DataSource.

Do you mind updating me if you are using datasource for populating your gridview data?

Sorry for my improper english.

Thanks =)


I use datasource to populate the gridview...can you be precise if u dont mind...

this is how i bounded the data...guess you would know this

if (!IsPostBack)
            con.ConnectionString = constr;
            SqlDataAdapter ada = new SqlDataAdapter("select * from Table3", con);
            ada.Fill(ds, "Table3");
            DataGrid1.DataSource = ds;
            GridView1.DataSource = ds;


Really thanks for your valuable response and thanks for your precious time too..


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.