how to bind dropdownlist with database value. [Resolved]

Posted by Joewilliam under Regular Expressions on 7/4/2011 | Points: 10 | Views : 6566 | Status : [Member] | Replies : 5
how to write bind method for dropdownlist to bind the database value.

William Mary


Responses

Posted by: Kapsystem on: 7/4/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi...

Here i have give the code to bind the database value to dropdownlist.

ddlCategory.Controls.Clear();
ddlCategory.DataSource = dsCategory.Tables[0];
ddlCategory.DataTextField = "Category";
ddlCategory.DataValueField = "CategoryID";
ddlCategory.DataBind();

Regards,

Joewilliam, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakn2 on: 7/5/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
public void bind()

{
sqldataadapter da=new sqldataadapter("select col1,col2 from table",cn);
dataset ds=new dataset();
da.fill(ds);
dropdownlist1.datatextfield="col1";
dropdownlist1.datavaluefield="col2";
dropdownlist1.datasource=ds;
dropdownlist1.databind();
}


Thanks&Regards
LakshmiNarayana Nalluri.

Joewilliam, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: SheoNarayan on: 7/4/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Hi Joewilliam,

I have written this article just for you http://www.dotnetfunda.com/articles/article1435-how-to-bind-dropdownlist-with-database-value-.aspx and others who may have the similar scenario.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Joewilliam, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CS1401 on: 7/5/2011 [Member] Starter | Points: 25

Up
0
Down
dropdown1.DataSource = datasourcename.Tables[0];

dropdown1.DataTextField = "Name";
dropdown1.DataValueField = "ID";
dropdown1.DataBind();


...

Joewilliam, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Susanthampy on: 7/5/2011 [Member] [MVP] Bronze | Points: 25

Login to post response