日期:2014-05-18  浏览次数:20526 次

datalist里嵌套了RadioButtonList,怎么取得RadioButtonList的值
<asp:datalist   id= "vote "   style= "Z-INDEX:   101;   LEFT:   264px;   POSITION:   absolute;   TOP:   112px "   runat= "server "   Width= "464px "   DataKeyField= "id "   RepeatColumns= "2 ">
<ItemTemplate>
<%#   DataBinder.Eval(Container.DataItem, "item_name ")%>
<asp:RadioButtonList   id= "ans "   runat= "server "> </asp:RadioButtonList>
</ItemTemplate>
</asp:datalist>
----------------------
RadioButtonLis是这样绑定数据的
private   void   vote_ItemDataBound(object   sender,   System.Web.UI.WebControls.DataListItemEventArgs   e)
{
                        Database   data=new   Database();
SqlDataReader   reader=null;
SqlParameter[]   prams={
  data.MakeInParam( "@item_id ",SqlDbType.Int,4,Convert.ToInt32(vote.DataKeys[(int)e.Item.ItemIndex].ToString())),
  };
data.RunProc( "zz_ans_list ",prams,out   reader);
RadioButtonList   d=(RadioButtonList)e.Item.FindControl( "ans ");
d.DataSource=reader;
d.DataTextField= "question ";
d.DataValueField= "id ";
d.DataBind();
data.Close();
data.Dispose();
}
-------------
谢谢

------解决方案--------------------
你要再哪里取?

... vote_ItemCommand(...
{
RadioButtonList d=(RadioButtonList)e.Item.FindControl( "ans ");
if(d != null) {
string val = d.SelectedValue;
// ...
}
}
------解决方案--------------------
RadioButtonList rbl = (RadioButtonList)vote.Items[i].FindControl( "ans ");
------解决方案--------------------
RadioButtonList List =(RadioButtonList)e.Item.FindControl( "ans ");
if(d != null)
{
foreach (ListItem lit in List.Items)
{
if (lit.Selected)
{
if (this.officeRadioButton.SelectedItem.Text == "选择得值 ")
{
..........................
}
}
}
}