在下拉列表中显示所需的值 [英] Show desired value in Dropdownlist

查看:97
本文介绍了在下拉列表中显示所需的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个下拉列表,它以编程方式与数据库绑定.我需要以编程方式显示控件中已经存在的所需项目.

在我的项目中,我有一个输入表单,其中有一个DropDownList,它通过代码与db绑定.在另一种形式中,单击编辑"时具有Gridview,在弹出窗口中也有相同的控件.但是我必须显示该控件中已经插入的值.

请帮我这样做.

问候,
Krishnamoorthy S

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

推荐答案

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();
            }
        }


在rowdatabound中使用上面的代码,其中ddExp是您的下拉列表


use the above code in rowdatabound where ddExp is your dropdown


您的实际问题是什么.可能是您没有获得查询字符串

为此用途
what is your actual problem. may be you are not getting the querystring

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


现在通过此qrystring绑定下拉列表和其他控件.


and now bind dropdown and other control via this qrystring.


try

try

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.


这篇关于在下拉列表中显示所需的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆