dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
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

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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">
   <Columns>
   <asp:BoundField  DataField="Field1" HeaderText="Field1"></asp:BoundField>
   <asp:BoundField  DataField="Field2" HeaderText="Field2"></asp:BoundField>
   .
   .
   .
   <asp:TemplateField>
   <ItemTemplate>
   <asp:Button ID="Button1" Runat=Server OnClick="Button1_Click" />
   </ItemTemplate>
   </asp:TemplateField>
   </Columns>
   </asp:GridView>
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.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date