在LoadPostData里如何取得数据

xjgsina 2012-04-06 08:59:14
我的dropdownlist控件在Render里重写了,所以取值如SelectedValue需要在LoadPostData里取,但dropdownlist控件只回发一个值SelectedValue。而SelectedItem和SelectedIndex均为空。在LoadPostData里dropdownlist数据也为空。怎么样样才能取到SelectedItem和SelectedIndex??

protected override void Render(HtmlTextWriter output)
{
string DDLValue;
string DDLText;

output.Write("<div class=\"ui-widget\">");
_ddlSource = (DataTable)ViewState["AutoListDataSource"];
_valueKeyName = (string)ViewState["AutoListValueKeyName"];
_textKeyName = (string)ViewState["AutoListTextKeyName"];
_isShowDetailed = (bool)ViewState["AutoListShowDetailed"];

if (_ddlSource != null)
{
if (_ddlSource.Rows.Count > 0)
{
foreach (DataRow dr in _ddlSource.Rows)
{
DDLValue = String.IsNullOrEmpty(_valueKeyName) == true ? dr[0].ToString() : dr[_valueKeyName].ToString();
DDLText = String.IsNullOrEmpty(_textKeyName) == true ? dr[1].ToString() : dr[_textKeyName].ToString();

ListItem li = new ListItem();
if (_isShowDetailed == true)
{
li.Text = DDLValue + "|" + DDLText;
}
else
{
li.Text = DDLValue;
}
li.Value = DDLValue;
this.Items.Add(li);

}

}
if (this.Items.Count > 0)
{
this.Items.Insert(0, new ListItem("", ""));
}
if (ViewState["AutoListSelectValue"] != null)
{
this.Items.FindByValue((string)ViewState["AutoListSelectValue"]).Selected = true;
}
}
base.Render(output);
output.Write("</div>");

}




public virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection)
{
string[] postDataValues = postCollection.GetValues(postDataKey);
if (postDataValues != null)
{
this.SelectedValue = postDataValues[0];
if (this.SelectedValue != null && (postDataValues[0] != null && !this.SelectedValue.Equals(postDataValues[0])))
{
this.SelectedValue = postDataValues[0];
ViewState["AutoListSelectValue"] = this.SelectedValue;
return true;
}
}
else
{
return false;
}
return false;

}

...全文
162 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xjgsina 2012-04-06
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
http://www.cnblogs.com/cathsfz/archive/2006/10/22/536425.html
[/Quote]
思路有点复杂了,看的不是很明白

62,267

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧