返回首页

您好

我赛伦德拉辛格。任何一个可以帮助我。

我想添加的DropDownList项目由函数值,但我想显示在DropDownList的顶部,选择关键字,按功能。

我下面的功能。

public void FillReportType()

    {

        con.Open();

        drpregtype.Items.Insert(0, new ListItem("--Select---", "----"));

        drpregtype.SelectedIndex = 0;

        da = new SqlDataAdapter("Select ResultType from tblresultType order by id ", con);

        DataTable dt = new DataTable();

        da.Fill(dt);

        drpregtype.DataSource = dt;

        drpregtype.DataValueField = "ResultType";

        //drpregtype.Items.Add.Add(new ListItem("--", "Select"));

        //drpregtype.Items.Insert(0, new ListItem("--Select---", "----"));

        //drpregtype.SelectedIndex = 0;

         drpregtype.DataBind();

        con.Close();

    }
感谢。

回答

评论会员:游客 时间:2012/02/07
Manish.Insan:您好赛伦德拉,只是修改你的代码:{C}希望这会给你的解决方案,你想要的。不要忘记标记为答案,如果它帮助。imgsrc=http://www.orcode.com/img/ico/smiley_smile.gif
michaelschmitt:嗨,

你有两个选择:

1。添加"选择"进入您的数据源(第一项),然后绑定你的下拉该数据源

或2。手动将您的项目添加到你的DropDownList不绑定到一个数据源。

您不能添加一个项目,并期望它显示UND绑定的数据源在同一时间。

此外,你应该得到的SQL摆脱你的看法。

希望这有助于
评论会员:游客 时间:2012/02/07
ManojDhobale:我同意上述解决方案ListItem的名字---选择---并使其作为选择codepreListIteml1=spanclass="code-keyword"new/spanListItem(spanclass="code-string""/spanspanclass="code-string"----Select----"/span,spanclass="code-string""/spanspanclass="code-string"none"/span);ListIteml2=spanclass="code-keyword"new/spanListItem(spanclass="code-string""/spanspanclass="code-string"abc"/span,spanclass="code-string""/spanspanclass="code-string"abc"/span);ListIteml3=spanclass="code-keyword"new/spanListItem(spanclass="code-string""/spanspanclass="code-string"xyz"/span,spanclass="code-string""/spanspanclass="code-string"xyz"/span);DropDownList1.Items.Add(l1);DropDownList1.Items.Add(l2);DropDownList1.Items.Add(l3);l1.Selected=spanclass="code-keyword"true/span;/pre/code所有最好的