2015年6月6日 星期六

dropdownlist 使用方法

參考引用來源:How can i set value and text dynamically to a dropdown list
--
If your datatable name is DtRecords then use following in Page Load to bind:

DropDownList1.DataSource = dtRecords;

DropDownList1.DataTextField = "cname";

DropDownList1.DataValueField = "cid";

DropDownList1.DataBind();

To get data on Button click;

string strCName = DropDownList.SelectedItem.Text; //Gets CName

string strCId = DropDownList.SelectedValue; //Gets CId

沒有留言:

張貼留言