Click here to Skip to main content
15,910,210 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to retreive value from grid view
in grid view i have template field and i want to retrieve value from label1 and assign this value in session variable
XML
<asp:TemplateField>

                   <ItemTemplate>
                   <table>
                    <tr>
                       <td rowspan="4">&nbsp;</td>
                       <td><a href="offerdetails.aspx"  style="text-decoration: blink">
                           <asp:Label ID="Label1" runat="server" Text='<%# Bind("AdTitle") %>'></asp:Label></a></td>
                        <td>
                            &nbsp;</td>
                   </tr>
Posted

You have to use FindControl.
Label lbl = gridview.Rows[index].FindControl("Label1") as Label;
Session["ssnLabelText"] = lbl.Text; 
 
Share this answer
 
Hi
By finding the label control you can store the data of the label to session

gridviewrow row=gridview1.rows[1] as gridviewrow;

 lable lbl=row.fincontrol("Label1");

Here the Label1 is the control in your gridveiw
 
Share this answer
 
Use FindControl for the Label place in ItemTemplate in a Gridview.

C#
Label lbltxt=(Label)gridview.Rows[index].FindControl("Label1");
Response.Write(lbltxt.Text)

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900