Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can't store data to a drop down list
Message
 
To
04/04/2007 18:38:59
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01210953
Message ID:
01212407
Views:
15
Hi Bonnie
I redid the code and have pasted it directly from the page.Load

string x;
x = reader["DOC_TYPE"].ToString();
DOC_TYPE.SelectedItem.Text = "ABC";

First two lines work ok
Third line gives a run time error: Object reference not set to an instance of an object

regards,
Gerard




>Where are these snippets of code?
>
>If both of these statements are one after the other, then I'd say that the reader object doesn't exist yet:
>
>DOC_MAN.SelectedItem.Text = "Anything";
>DOC_MAN.SelectedItem.Text = reader["DOC_MAN"].ToString();
>
>However, you say that this snippet works fine:
>
>string x;
>x=reader["DOC_MAN"].ToString();
>
>which means that the reader object *does* exist, at least where you put this code snippet.
>
>If all 4 of these lines of code are together, one after the other, then your "object reference not set to an instance of an object" error is not making any sense.
>
>~~Bonnie
>
>
>
>>Hi Bonnie.
>>Did what you suggested and it worked up to a point:-
>>DOC_MAN.SelectedItem.Text = "Anything"; works fine
>>DOC_MAN.SelectedItem.Text = reader["DOC_MAN"].ToString();
>> compiled ok but gave a run time--> object reference not set to an instance of an object.
>>
>>However, the following ran ok:
>>string x;
>>x=reader["DOC_MAN"].ToString();
>>
>>There is just plain text in the DOC_MAN field that comes from a table.
>>
>>Regards,
>>Gerard
>>
>>
>>
>>>Gerard,
>>>
>>>I haven't checked this out (don't currently have a web project open), but according to the docs, there *is* a .Text property for the DropDownList ... maybe it just doesn't show up in Intellisense? However, I suggest that you try this instead:
>>>
>>>
>>>  DOC_MAN.SelectedItem.Text = "ANYTHING";
>>
>>>
>>>
>>>Just a guess ...
>>>
>>>~~Bonnie
>>>
>>>>Hi
>>>>
>>>>I have a web form with a Drop Down List(DOC_TYPE) which is populated from a table. The populating etc is working fine
>>>>Storing data to the table in insert,update is ok. I use
>>>> DOC_TYPE.SelectedValue
>>>>
>>>>But when I try to go the other way (Store the Table value to the Form Field)
>>>> DOC_MAN.Selectedtext = "ANYTHING";
>>>>
>>>>There is no DOC_TYPE.Text so I cant use that ?
>>>>
>>>>It blows out the Web Page and does not load
>>>>
>>>>Any Ideas ?
>>>>
>>>>Regards,
>>>>Gerar
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform