Click here to Skip to main content
16,021,430 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello programmers, got a few question here. Im getting an error saying Object reference not set to an instance of an object. on this part Label1.Text = Request.QueryString("CourseCatID").ToString But I think my syntax is correct. Any Ideas?
XML
<asp:TemplateField HeaderText="Edit">
    <ItemTemplate>
         <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl='<%#"CourseList.aspx?ID=" & Eval("CourseCatID")%>'  Text="Edit Courses"></asp:LinkButton>
   </ItemTemplate>
</asp:TemplateField>

Updated:
I think my requestquerystring is not null since ive got this on address bar
http://localhost:4543/Trainingplan/CourseList.aspx?ID=6
Posted
Updated 4-Oct-11 22:25pm
v2

Make sure that Request.QueryString("CourseCatID") is not null.
If it is, then a ToString() on null will throw the error you are getting.

If you need more information on passing multiple values to a hyperlink field, see here[^].
 
Share this answer
 
v3
ur passing PostBackUrl='<%#"CourseList.aspx?ID=" & Eval("CourseCatID")%> so use Request.QueryString("ID").ToString
 
Share this answer
 
C#
<asp:linkbutton id="lnkEdit" postbackurl="<%# "CourseList.aspx?ID=" + Eval("ID")%>" text="Edit Courses" runat="server" xmlns:asp="#unknown"></asp:linkbutton>


and in redirected page means on CourseList.aspx page
check like
C#
string id = Request.QueryString["ID"].ToString();

if(id != "" or id != null)
{
    //do your code for what you whant that id.
}
 
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