嗨,有没有其他人遇到过类似的问题,如下所述
我有一个带有几个 DDL 和文本框的网络表单,其中一些有回发,一些没有
DDL 有 3 或 4 个值,例如 Yes 、 No 或经常、Regularly、Never
用户可以选择值并将其选择结果保存在 sql server 上,并在保存时生成记录号。
他还能够通过相同的记录号检索他的结果 通过一个名为 RecordSrchId 的子例程,所有文本框都被填充 大多数 DDL 被填充并且结果被选中,但一些 DDL 没有被选中。
例如,DDL 将在项目列表中具有 Yes, No 结果作为值。从 sql 检索到的数据显示在数据表中,值通过项目的正确 ID 向下级联,例如“mydatatable.Tables(0).Rows(0)(2).ToString”,其中我的数据表是数据表(2) 是项目编号,我从 mydatatable 获得一个值,因为我已经使用 Label 控件对其进行了测试,因此它不会返回 null 并且 DDl 具有正确的大小写格式的正确值列表,但由于某种原因它会给出我下面有个错误
你调用的对象是空的。
描述:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
源错误:
Line 1148:
Line 1149: crane_requirement_Frequency_40T0.Items.FindByText(mydatatable.Tables(0).Rows(0)(32).ToString).Selected = True Line 1150: Line 1151:
Source File: C:\inetpub\wwwroot\aspx\factfind\Default.aspx.vb Line: 1149
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
FactFindMenu.recordidsrch() in C:\inetpub\wwwroot\aspx\factfind\Default.aspx.vb:1149
FactFindMenu.Srch_Record_Click(Object sender, EventArgs e) in C:\inetpub\wwwroot\aspx\factfind\Default.aspx.vb:1090
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
检索日期的子程序如下
Private Sub recordidsrch()
Dim searchFactfnd As New SearchFactFnd ' custom class used to retrive data From sql server
Dim mydatatable As New Data.DataSet ' Dataset/table used
mydatatable = searchFactfnd.FactFNDTableID(Rcrd_num_Txt.Text) ' populates the dataset with the function FactFNDTableID via a record Id gained from a textbox and function returns a dataset/table
contact_name.Text = mydatatable.Tables(0).Rows(0)(1).ToString
crane_hireCranesFrequency.Items.FindByText(mydatatable.Tables(0).Rows(0)(30).ToString)
crane_spendPA.Text = mydatatable.Tables(0).Rows(0)(31).ToString
crane_requirement_Frequency_40T.Items.FindByText(mydatatable.Tables(0).Rows(0)(32).ToString).Selected =True ' Line give error if i include .Selected =True
Label4.Text = mydatatable.Tables(0).Rows(0)(32) ' gives me a result that can be found in the DDL
end sub
The HTML code dor the DDL is
<asp:DropDownList ID="crane_requirement_Frequency_40T" runat="server" CssClass="largeinput" AutoPostBack="True">
<asp:ListItem>Crane Requirements Frequency</asp:ListItem>
<asp:ListItem>Regularly</asp:ListItem>
<asp:ListItem>Often</asp:ListItem>
<asp:ListItem>Seldom</asp:ListItem>
<asp:ListItem>Never</asp:ListItem>
</asp:DropDownList>
I have tried several variations of the below
Items.FindByText(mydatatable.Tables(0).Rows(0)(32).ToString).Selected =True
Items.FindByvalue(mydatatable.Tables(0).Rows(0)(32).ToString).Selected =True
ddl.selectedvalue
ddl.selecteditem
if not ispostback then
'populate
end if
ddl.clearcontents
尝试将 html ddl 重写为下面并尝试上面的变体不起作用
<asp:DropDownList ID="crane_requirement_Frequency_40T" runat="server" CssClass="largeinputd">
<asp:ListItem Text="Crane Requirements Frequency"Value="" />
<asp:ListItem Text="Regularly" Value="Regularly" />
<asp:ListItem Text="Often" Value="Often" />
<asp:ListItem Text="Seldom" Value="Seldom" />
</asp:DropDownList>
现在严重卡住了任何应不胜感激的帮助我知道数据集的值是正确的而不是空值并且DDL中存在的值可能会回发导致这种情况