使用querrystring的asp.net Gridview [英] asp.net Gridview using querrystring
问题描述
您好,程序员,这里有几个问题.我在这部分 Label1.Text = Request.QueryString("CourseCatID").ToString 上遇到错误,提示Object reference not set to an instance of an object.
,但是我认为我的语法是正确的.有任何想法吗?
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?
<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>
已更新:
我认为我的requestquerystring不为null,因为ive在地址栏上收到了此消息
http://localhost:4543/Trainingplan/CourseList.aspx?ID=6
Updated:
I think my requestquerystring is not null since ive got this on address bar
http://localhost:4543/Trainingplan/CourseList.aspx?ID=6
推荐答案
确保Request.QueryString("CourseCatID")
不为null.
如果是,则在null上的ToString(
)会引发您得到的错误.
如果您需要有关将多个值传递给超链接字段的更多信息,请参见此处 [ ^ ].
Make sure thatRequest.QueryString("CourseCatID")
is not null.
If it is, then aToString(
) on null will throw the error you are getting.
If you need more information on passing multiple values to a hyperlink field, see here[^].
ur通过PostBackUrl =''<%#"CourseList.aspx?ID ="&Eval("CourseCatID")%>因此请使用Request.QueryString("ID").ToString
ur passing PostBackUrl=''<%#"CourseList.aspx?ID=" & Eval("CourseCatID")%> so use Request.QueryString("ID").ToString
<asp:linkbutton id="lnkEdit" postbackurl="<%# "CourseList.aspx?ID=" + Eval("ID")%>" text="Edit Courses" runat="server" xmlns:asp="#unknown"></asp:linkbutton>
并在重定向页面中意味着在CourseList.aspx页面上
像
一样检查
and in redirected page means on CourseList.aspx page
check like
string id = Request.QueryString["ID"].ToString();
if(id != "" or id != null)
{
//do your code for what you whant that id.
}
这篇关于使用querrystring的asp.net Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!