Asp.net 从中继器内的单选按钮获取所选单选按钮列表值

Asp.net 从中继器内的单选按钮获取所选单选按钮列表值,asp.net,repeater,radiobuttonlist,Asp.net,Repeater,Radiobuttonlist,我在中继器里有一个无线电按钮列表。我正在展示一个屏幕截图。我在中继器的标题模板中有列标题。在项目模板中,我有4个字段/列。第三个字段是单选按钮列表。例如,如果我在“测试任务2”行中选择“是”单选按钮,我需要回发并保存该记录的值(回发到数据库)。我的中继器可能会显示多行字段和单选按钮列表 if (Repeater1.Items.Count > 0) { for (int count = 0; count < Repeater1.Items.Count; count++)

我在中继器里有一个无线电按钮列表。我正在展示一个屏幕截图。我在中继器的标题模板中有列标题。在项目模板中,我有4个字段/列。第三个字段是单选按钮列表。例如,如果我在“测试任务2”行中选择“是”单选按钮,我需要回发并保存该记录的值(回发到数据库)。我的中继器可能会显示多行字段和单选按钮列表

if (Repeater1.Items.Count > 0)
{
    for (int count = 0; count < Repeater1.Items.Count; count++)
    {
        RadioButton rd1 = (RadioButton )Repeater1.Items[count].FindControl("ID1");
        RadioButton rd2 = (RadioButton )Repeater1.Items[count].FindControl("ID2");
        RadioButton rd3 = (RadioButton )Repeater1.Items[count].FindControl("ID3");
        if (rd1.Checked)
        {

        }
        if (rd2.Checked)
        {

        }
       if (rd3.Checked)
        {

        }
    }
}
if(Repeater1.Items.Count>0)
{
对于(int count=0;count
我在gridview中使用过类似的东西,希望这能帮助您 让我们考虑一下我们有2个按钮

<asp:RadioButton ID="rb_Yes" runat="server" GroupName="GpName" Text="Yes" OnCheckedChanged="rb_Yes_Click" AutoPostBack="true" />
<asp:RadioButton ID="rb_No" runat="server" GroupName="GpName" Text="No" OnCheckedChanged="rb_No_Click" AutoPostBack="true"/>
希望这能帮助你

试试这个

protected void rb_Yes_Click(object sender, EventArgs e)
{ 
    RadioButton rb_Yes = (RadioButton)sender;
    GridViewRow grid_row = (GridViewRow)rb_Yes.NamingContainer;
    if(((RadioButton)grid_row.FindControl("rb_Yes")).Checked==true)
    {
//Action that you want to implement
    }
}

protected void btnSave_Click(object sender, EventArgs e)
    {
        foreach (RepeaterItem item in Repeater1.Items)
        {
            // Checking the item is a data item
            if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
            {
                var rdbList = item.FindControl("RadioButtonList1") as RadioButtonList;
                // Get the selected value
                string selected = rdbList.SelectedValue;
            }
        }
    }

此单选按钮列表是否为Yes、No和N/A的单独单选按钮?Yes、No和N/A是作为一个radio按钮列表的一部分的列表项。我已在radio button列表中将建议的BTN保存单击方法指定给OnSelectedIndex。我还将AutoPostBack设置为“true”。当我选择一个不同的单选按钮时,我的页面会发回,但不会触发btnSave\u Click方法。我该如何连接?我刚才问的问题在这里得到了回答: