Login | Register   
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


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

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