为学ASP刚开通了blog

看了  朱晔的《ASP.NET第一步》, 其中一个数据绑定一直没搞定, 于是就上来了。

具体情况是这样的, 我对RadioButtonList进行了数据绑定, 但总是取不到

选择的值, SelectedIndex总是为-1, 好像从来没选中过...

以下是建立数据源代码

1 DirectoryInfo di = new DirectoryInfo(@"F:\");
2 DirectoryInfo[] DataSource4 = di.GetDirectories();

绑定到控件

// RadioButtonList 数据绑定
RadioButtonList1.DataSource = DataSource4;
RadioButtonList1.DataTextField = "Name";
RadioButtonList1.DataValueField = "FullName";
RadioButtonList1.DataBind();

SelectedIndexChanged事件处理代码

RadioButtonList rbl = sender as RadioButtonList;
if (rbl != null)
{
    Response.Write(rbl.SelectedItem.Value);
}

网页运行时, 那个数据是可以出来的, 但是选择之后, 就一直提示SelectedIndex值出错, 

调了下, 发现其一直是-1, 根本没变过..

posted on 2011-05-21 22:56  真不是Geek  阅读(286)  评论(6)    收藏  举报

导航