Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: C#
Expertise: Beginner
Apr 25, 2005



Application Security Testing: An Integral Part of DevOps

Access GridView Container Row Items from the Button Click Event

Assume Each GridViewRow contains Field1, Field2,.... Button:

<asp:GridView ID="GridView1" Runat="server" DataSourceID="sdsDataSource">
   <asp:BoundField  DataField="Field1" HeaderText="Field1"></asp:BoundField>
   <asp:BoundField  DataField="Field2" HeaderText="Field2"></asp:BoundField>
   <asp:Button ID="Button1" Runat=Server OnClick="Button1_Click" />
To access the other items in the same row from inside the button click event, you need to find the corresponding GridViewRow in which the button is placed.

GridViewRow grdRow = (GridViewRow)Button1.Parent.Parent;

   void Button1_Click(object o, EventArgs e)
   Button Button1 = (Button)o;
   GridViewRow grdRow = (GridViewRow)Button1.Parent.Parent;
   string strField1 = grdRow.Cells[0].Text;
   string strField2 = grdRow.Cells[0].Text;
Note: Applicable only for ASP.NET 2.0.

Jaya Nehru Kumar
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date