Friday, March 16, 2012

Object reference not set to an instance of an object.

Hi All,
i get the following error with the follwing code:
Object reference not set to an instance of an object.

sqlString = "select event,study from tblEvents where PATIENTID = @dotnet.itags.org.id"
cmd = New OleDbCommand(sqlString, cnOleDb)
cmd.Parameters.Add("@dotnet.itags.org.id", id)
rdr = cmd.ExecuteReader()
While rdr.Read()
'-I got the error on the following 2 stmts.
Drop_ReportedBy.Items.FindByText(rdr("event")).Selected = True
Drop_Study.Items.FindByText(rdr("Study")).Selected = True
End While
rdr.Close()

I tried to execute the same code with response.write then it works fine.
Response.Write(rdr("event"))
Response.Write(rdr("Study"))

Drop_ReportedBy and Drop_Study are two drop down lists

Can anyone help
Thanks in advanceseems to be a problem of postback.
Before writing Drop_ReportedBy.Items.FindByText(rdr("event")).Selected = True

check

Drop_ReportedBy.Items.Count (I think it's 0)

Hope it helps
the count is 2

any other idea?

Appreciate your help
An After Lunch though

ListItem l_obj_ListItem=null;
l_obj_ListItem = Combo.Items.FindByText(<text to find>);
if(l_obj_ListItem != null)
{
Combo.ClearSelection();
l_obj_ListItem.Selected = true;
}

Hope it helps

0 comments:

Post a Comment