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

急,关于嵌套radiobuttonlist的问题
gridview   中嵌套radiobuttonlist(模板列),如何根据gridview的id(datakey)
来动态绑定radiobuttonlist的值(直接绑定不行),并且当选择radiobuttonlist的其他值时,自动更新数据库,虽然知道是selectedchanged事件,但如何得到它是第几行

------解决方案--------------------
<asp:GridView ID= "GridView1 " runat= "server " AutoGenerateColumns= "False " OnRowDataBound= "GridView1_RowDataBound ">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButtonList ID= "RadioButtonList1 " runat= "server " AutoPostBack= "True " OnSelectedIndexChanged= "RadioButtonList1_SelectedIndexChanged ">
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

------------------------------------------------

public static string ConnectionString = "Data Source=服务器名;Initial Catalog=数据库名;Persist Security Info=True;User ID=sa;Password=密码 ";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string strSQL = "Select * From 表名 ";
SqlDataAdapter da = new SqlDataAdapter(strSQL, ConnectionString);
DataTable dt = new DataTable();
da.Fill(dt);
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
RadioButtonList rbl = (RadioButtonList)e.Row.Cells[0].FindControl( "RadioButtonList1 ");
if (rbl != null)
{
//在此写绑定RadioButtonList代码
}
}
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
int index = ((GridViewRow)((RadioButtonList)sender).Parent.Parent).RowIndex;
}
------解决方案--------------------
不会啊
只能帮顶了