By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,866 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,866 IT Pros & Developers. It's quick & easy.

ASP.NET ---- How to get database value as dropdownlist selected value

P: 30
Hi All,

I have an editable datagrid with 10 columns, one of those is ddl column which I used for showing the status....

[ Please note : Status is a template column with an item template as label... and edit item template as dropdownlist]

By default all the columns are readonly, when user clicks edit, status ll be enabled and im getting the values in the grid.......

say, following are the values in status


If i update my status as Expert it should show Expert in my next edit, but dropdownlist always takes first value ..... Can any one help me how to fetch the database value as dropdownlist selected value......

Thanks a lot in Advance ......
Nov 25 '08 #1
Share this Question
Share on Google+
1 Reply

P: 55
Attach a databound event to your dropdownlist on .aspx page e.g.

<asp:DropDownList ID="ddl" runat="server" OnDataBound="ddl_DataBound" />

Then in code behind retrieve value from database and make it selected value on drop down list e.g.

protected void ddl_DataBound(object sender, EventArgs e)
//Connect to SQL and run select statement to retrieve value
//i.e. SELECT Status FROM Table WHERE......

SqlDataReader rdr = cmdUser.ExecuteReader();

while (rdr.Read())
ddl.Items.FindByText(rdr.GetString(0)).Selected = true;
Nov 27 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.