从中继器内的单选按钮获取选定的单选按钮列表值

发布于 2024-11-24 08:54:21 字数 219 浏览 3 评论 0原文

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

屏幕截图

I have a radiobuttonlist inside a repeater. I am showing a screenshot of what this looks like. I have column headers inside the header template of the repeater. In the item template, I have the 4 fields/columns. The 3rd field is a radio button list. If, for example, I select the "Yes" radio button in the "Test Task 2" row - I need to postback and save the value of that record (back to a database). My repeater could potentially display many rows of fields and radio button lists.

screenshot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

自由如风 2024-12-01 08:54:21

试试这个


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;
            }
        }
    }

Try this


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;
            }
        }
    }

空城旧梦 2024-12-01 08:54:21
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)
{
    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)
        {

        }
    }
}
旧伤慢歌 2024-12-01 08:54:21

我在 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"/>

只需使用 oncheckedChanged 事件进行回发
并在 .cs 页面中使用类似这样的代码我相信这可以帮助你

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
    }
}

希望这可以帮助你

I have used something in gridview like this hope this can help you
Let us consider we have 2 buttons

<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"/>

Just use the oncheckedChanged event for post back
and in .cs Page use the code something like this I m sure this can help you

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
    }
}

Hope this can help you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文