Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I have a dropdownlist which is binded with database programatically. I need to show programatically the desired item which is already in the control.

In my project, I have an entry form in that I've a DropDownList which binds with db through code. In another form have Gridview while clicking edit, in popup window the same control is there. But I have to show the already inserted value in that control.

Please help me to do so.

Regards,
Krishnamoorthy S
Posted

C#
DataRowView drview = (DataRowView)e.Row.DataItem;
        if ((e.Row.RowState & DataControlRowState.Edit) > 0)
        {
            DropDownList ddExp = (DropDownList)e.Row.FindControl("ddExp");
            if (ddExp != null)
            {
                ddExp.Text = drview["Expense_Type"].ToString();
            }
        }

use the above code in rowdatabound where ddExp is your dropdown
 
Share this answer
 
v3
Comments
Karthik Harve 3-Jan-12 7:10am    
[Edit] pre tags added.
krishnaspmoorthy 3-Jan-12 7:35am    
this is not my requirement.

While clicking the grid, get the id and pass the id to a popup window. On that window I get the values from db according to the id and assign the values to the controls which are in that window. Previously mentioned dropdownlist is in this window. Here I have to show the value corresponding to the value I already inserted.

Hope that you understood my problem. Kindly help me to do.

Regards,
Krishnamoorthy S
what is your actual problem. may be you are not getting the querystring

for that use
C#
string qrystring=Request.querystring["db_column"].tostring();

and now bind dropdown and other control via this qrystring.
 
Share this answer
 
v2
Comments
krishnaspmoorthy 3-Jan-12 7:43am    
actually i got the all the values. But not able to show the value in the dropdownlist corresponding to the value which i read from the db.

Regards,
Krishnamoorthy S
Wendelius 3-Jan-12 10:14am    
Pre tags added
try

C#
string somevariable=dr["dbcolumn"].toString(); //if you are using datareader

 string somevariable=dt.rows[0]["dbcolumn"].tostring(); //if you are using datatable

 dropdown.selecteditem.text=somevariable;  //in this case somevariable should be there in dropdownlist.
 
Share this answer
 
v2

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