hi,
I had a field in table it's called child_sex and it's type is Yes/No
(I work with MS Access DataBase)
and I read user's choice from dropdownlist
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem Value="0">son</asp:ListItem>
<asp:ListItem Value="1">girl</asp:ListItem>
</asp:DropDownList>
but I want to edit the record so I fetch data like this from database
DropDownList1.Items.Clear();
DropDownList1.AppendDataBoundItems = true;
DropDownList1.Items.Add(new ListItem("son","0"));
DropDownList1.Items.Add(new ListItem("girl", "1"));
DropDownList1.Items.FindByValue(dr["child_sex"].ToString()).Selected = true;
and I face with this error
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 48: DropDownList1.Items.Add(new ListItem("son","0"));
Line 49: DropDownList1.Items.Add(new ListItem("girl", "1"));
Line 50: DropDownList1.Items.FindByValue(dr["child_sex"].ToString()).Selected = true;
what's the problem?
thanks a lot