my requirement is store the drop down list items filled dynamically(from server side) in a user control on submit button. problem # On submit button i am unable to get the drop down list items on server side they are null. Can you guys please suggest me what is the best way to acesss the drop down list items
on page load
ddlCCFirstBTFXMethod.DataSource = tdatasource;
ddlCCFirstBTFXMethod.DataTextField = "开发者_JAVA百科Key";
ddlCCFirstBTFXMethod.DataValueField = "Value";
ddlCCFirstBTFXMethod.DataBind();
on submit
var a = ddlCCFirstBTFXMethod.Items.Cast<ListItem>().ToDictionary( i => i.Text,i => i.Value);
You should have a If(!IsPostBack())
so you code will look something like this.
if (!IsPostBack())
{
ddl.DataSource = source;
ddl.DataTextField = "Key";
ddl.DataValueField = "Value";
ddl.DataBind();
}
On Submit
foreach(var item in ddl.Items)
{
Response.Write(String.Format("Text : {0}, Value: {1}",item.Text, item.Value);
}
精彩评论