在下拉列表中显示列表值 [英] Displaying listvalue in dropdownlist

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

问题描述

我想通过数据表在下拉列表中显示记录.一切正常,但下拉列表始终在运行时显示第一个索引值.但是,数据表中的记录是不同的.
在错误的地方查看我的代码:

I want to display the record in dropdownlist through datatable. Everything works fine, but the dropdownlist always show the first index value at runtime. However, the record in datatable is different.
See my code where I am wrong:

{
  nsBusinessLogicLayer.BusinessesInfo objBusinessesInfo = new nsBusinessLogicLayer.BusinessesInfo();
  DataTable dt = objBusinessesInfo.Select(Convert.ToInt64(LoginUserId));

  ddlCountyr.SelectedValue = dt.Rows[0]["StateId"].ToString();
}
if (dt.Rows[0]["CountryId"] != "")
{
  ddlState.SelectedValue = dt.Rows[0]["CountryId"].ToString();
}

推荐答案

ddlCountyr.SelectedValue = dt.Rows[0]["StateId"].ToString();


您已经在此处编写了代码!

您需要做的是:


You have written the code here for that!

What you need to do is:

ddlCountry.Datasource = dt;
ddlCountry.DataTextField = "CountryId";
ddlCountry.DataValuefield = "CountryId"; // can change it to anything
ddlCountry.DataBind();


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

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