Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friend

i have retrive value from database and display in dropdown list, but its give error like
"Object reference not set to an instance of an object."

here is code :-

C#
db.GetAddressByOrderID(Convert.ToInt32(txtorder.Text));

                if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                {
                     DrpShippingState.Enabled = true;
                     DrpBillingState.SelectedItem.Text = ds.Tables[0].Rows[0]["BillingState"].ToString();    
                     DrpShippingState.Enabled = true;
                     DrpShippingState.SelectedItem.Text = ds.Tables[0].Rows[0]["ShippingState"].ToString();
                }


how can i fetch state name in drop down..???

Thank You To all in Advance
Posted
Comments
Rajesh Kariyavula 6-Nov-12 1:18am    
Is the Dropdown Data source set before setting a selected value for it?
Bhushan Shah1988 6-Nov-12 1:23am    
did u bind datasource to drop-down list?
Yatin chauhan 6-Nov-12 1:32am    
Hi Rajesh,
now i get the probelm. i have bind data source in dropdown . but i bind country list after state .now i bind country before state and based on that bind state so its solve the problem..
Thank You Sir..!!!
manognya kota 6-Nov-12 1:57am    
Please mark the question as solved:)

1 solution

Before doing anything inside if construct add this code

C#
DrpShippingState.DataSource = ds.Tables[0];
 DrpShippingState.DataTextField = "BillingState";
 DrpShippingState.DataValueField = "BillingState";
 DrpShippingState.DataBind();

 DrpShippingState.Items.Insert(0, new ListItem("Select State"));
 
Share this answer
 
v2
Comments
Yatin chauhan 6-Nov-12 7:26am    
Thanks For Reply..
i solve that problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900