Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, all

Here my problem is i dont know how to display the data from DB in database


My Code is

SQL
ddlprivelege.Items.Insert(0, new ListItem("User", "0"));
            ddlprivelege.Items.Insert(1, new ListItem("Enroller", "1"));
            ddlprivelege.Items.Insert(2, new ListItem("Admin", "2"));
            ddlprivelege.Items.Insert(3, new ListItem("SuperAdmin", "3"));
            ddlprivelege.Items.FindByValue(Dtab.Rows[0]["Privilege"].ToString()).Selected = true;


when i try this i got object ref error how to make it easy

Thanks...
Posted
Comments
Mayank Vashishtha 20-Aug-14 2:41am    
What in the world are you trying to do? It's unclear. Use Improve Question widget and make it more clear to understand.

check whether you have data in Dtab or not.

C#
if(Dtab!=null && Dtab.Rows.Count>0)
{
ddlprivelege.Items.FindByValue(Dtab.Rows[0]["Privilege"].ToString()).Selected = true;
}
 
Share this answer
 
v2
If Dtab.Rows[0]["Privilege"].ToString() this returns Text then try to use
ddlprivelege.Items.FindByText(Dtab.Rows[0]["Privilege"].ToString()).Selected = true;


If Dtab.Rows[0]["Privilege"].ToString() this returns ID then try to use
ddlprivelege.Items.FindByValue(Dtab.Rows[0]["Privilege"].ToString()).Selected = true;


And you have to sure Dtab.Rows[0]["Privilege"].ToString() value should exists in dropdown from your text or id of inserted data
 
Share this answer
 
check null value for Dtab like
if(Dtab!=null){}
 
Share this answer
 
Use this code...

ddlEmployee.Items.FindByText(Dtab.Rows[0]["Privilege"].ToString()).Selected = true;


thanks.
 
Share this answer
 

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