本文介绍了将数据表绑定到表单中的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我创建了2个国家和城市的数据表。拥有state_id state_name。我希望下拉列表由数据表(状态)中插入的数据填充。所以如何将表绑定到下拉列表。



protected void Page_Load(object sender,EventArgs e)

{

if(!IsPostBack)

{



DataTable dt = new DataTable();

ddlstate.DataSource = state;

ddlstate.DataTextField =state_name;

ddlstate.DataValueField =state_id;

ddlstate.DataBind();

}



protected void ddlstate_SelectedIndexChanged(object sender,EventArgs e)

{

string sId = ddlstate.SelectedValue.ToString();

string sName = ddlstate.SelectedItem.ToString();

}



这不起作用..

hello,

i have created 2 datatables state and city. having state_id state_name. And i want the dropdownlist to be filled by the data inserted in datatable(state). so how to bind tables to dropdown.

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

DataTable dt = new DataTable();
ddlstate.DataSource = state;
ddlstate.DataTextField = "state_name";
ddlstate.DataValueField = "state_id";
ddlstate.DataBind();
}

protected void ddlstate_SelectedIndexChanged(object sender, EventArgs e)
{
string sId = ddlstate.SelectedValue.ToString();
string sName = ddlstate.SelectedItem.ToString();
}

this is not working..

推荐答案


这篇关于将数据表绑定到表单中的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 20:29