开发者

Dynamically loaded drop down list from server side are not available to access on submit from server side

开发者 https://www.devze.com 2023-03-17 17:32 出处:网络
my requirement is store thedrop down list itemsfilled 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

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消