Hi has anyone else come across a similar issue as described below

I have a web form with several DDL and text boxes some of them have post backs some dont

the DDLs have 3 or 4 Values like Yes , No or Often, Regularly, Never

a user is able to select the values and save his selection results on a sql server and a record number is generated on the save.

he is also able to retrieve his results via the same record number Via a subroutine called RecordSrchId all the text boxes get populated most of the DDLs get populated and results are selected but some of the DDLs dont get selected.

The DDLs for example will have Yes, No results as values in the list of items. The retrieved data from the sql is presented in a datatable and the value is cascaded down via the correct ID of the items for example "mydatatable.Tables(0).Rows(0)(2).ToString" where my datatable is the datatable and (2) is the item number i get a value from mydatatable as i have tested this with a Label control so its not returning null and the DDl have the correct list of values also in the correct case formats but for some reason it will give me an error below

Object reference not set to an instance of an object.




Description:

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.

Source Error:



Line 1148:
Line 1149: crane_requirement_Frequency_40T0.Items.FindByText(mydatatable.Tables(0).Rows(0)(32).ToString).Select ed = 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

the subroutine to retrive the date is below





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).Selecte d =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

<aspropDownList 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>

</aspropDownList>



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

tried rewriting the html ddl to below and try variations above did not work

<aspropDownList 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" />

</aspropDownList>



seriously stuck now any help whould be appreciated i know the values fro the data set are correct and not null and the values exist in the DDL could post back be causing this