.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Steve Jackman
Imran Ghani
Santhakumar Munuswamy

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

pass label text from gridview to a query string

Posted By: Pawan kumar Shukla     Posted Date: April 26, 2011    Points:5   Category :ASP.Net
<div>
<asp:Label ID="lblin" runat="server" Text="Label"></asp:Label>
<asp:GridView ID="gv_show_vacc" CssClass="list-wrap" runat="server"
GridLines="None" AutoGenerateColumns="false" AllowPaging="True"
PageSize="15" onselectedindexchanged="gv_show_vacc_SelectedIndexChanged"
AutoGenerateSelectButton="True" >
<Columns>
<asp:TemplateField ItemStyle-Width="270px" ItemStyle-HorizontalAlign="Justify" >
<ItemTemplate>

<asp:Label ID="lblpos" runat="server" Text='<%# Eval("id")%>'></asp:Label>
<asp:LinkButton ID="lbtnvac" CommandName="show" runat="server"><%#Eval("p_name")%></asp:LinkButton>

</ItemTemplate>

<ItemStyle HorizontalAlign="Justify" Width="270px"></ItemStyle>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>





protected void gv_show_vacc_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (GridViewRow gr in gv_show_vacc.Rows)
{
LinkButton lbtnvac = gv_show_vacc.FindControl("lbtnvac") as LinkButton;
Label lblpos = gv_show_vacc.FindControl("lblpos") as Label;
Response.Write(lblpos.Text);
}
}




ERROR:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Response.Write(lblpos.Text);= Line

Responses
Author: Sunil Yadav       [Moderator]      
Posted Date: April 26, 2011     Points: 20   

Hi,

Modify your code as shown below

protected void gv_show_vacc_SelectedIndexChanged(object sender, EventArgs e)
{

if (e.Row.RowType == DataControlRowType.EmptyDataRow)
{

foreach (GridViewRow gr in gv_show_vacc.Rows)
{
LinkButton lbtnvac = gv_show_vacc.FindControl("lbtnvac") as LinkButton;
Label lblpos = gv_show_vacc.FindControl("lblpos") as Label;
Response.Write(lblpos.Text);
}
}}



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend