【问题标题】:Need help setting the same values for radiobutton list in gridview in ItemTemplate based on selected value radiobuttion list in HeaderTemplate需要帮助根据 HeaderTemplate 中的选定值单选按钮列表在 ItemTemplate 的 gridview 中为单选按钮列表设置相同的值
【发布时间】:2016-02-17 07:14:07
【问题描述】:

我的任务是创建一个 Gridview,其中用户单击标题 (rblDifficulty) 上的单选按钮列表和下面行中的所有单选按钮列表 (rblDiff) 将被设置为相同的值。我已经使用复选框和 jquery 查看并修改了示例,但没有成功。希望有人可以指导我

 <asp:GridView ID="gvData" runat="server" EmptyDataText="No Data" DataKeyNames="ID"  AllowPaging="true" PageSize ="15"
        class="" AutoGenerateColumns="False" OnPageIndexChanging="OnPaging">
        <Columns>

            <asp:TemplateField HeaderText="Name">
                <ItemTemplate>
                    <asp:Label ID="lblName" runat="server" Text='<%# Eval("Name")%>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="ID">
                <ItemTemplate>
                    <asp:Label ID="lblID" runat="server" Text='<%# Eval("ID")%>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>                                  
            <asp:TemplateField HeaderText="Difficulty">
              <HeaderTemplate>
              <asp:RadioButtonList  ID="rblDifficulty"  runat="server">
                        <asp:ListItem Text="Easy" Value="0"></asp:ListItem>
                        <asp:ListItem Text="Medium" Value="Y"></asp:ListItem>
                        <asp:ListItem Text="Hard" Value="F"></asp:ListItem>
              </asp:RadioButtonList>
              </HeaderTemplate> 
                <ItemTemplate>
                    <asp:RadioButtonList ID="rblDiff" runat="server">
                        <asp:ListItem Text="Easy" Value="0"></asp:ListItem>
                        <asp:ListItem Text="Medium" Value="Y"></asp:ListItem>
                        <asp:ListItem Text="Hard" Value="F"></asp:ListItem>
                    </asp:RadioButtonList>
                </ItemTemplate>
            </asp:TemplateField>

        </Columns>
    </asp:GridView>

更新:jomsk1e 在这方面帮助了我

 Protected Sub rblDifficulty_onChanged(sender As Object, e As EventArgs)
    Dim rblDifficulty As RadioButtonList = DirectCast(gvData.HeaderRow.FindControl("rblDifficulty"), RadioButtonList)
    Dim selectedValue__1 As String = rblDifficulty.SelectedValue

    For Each row In gvData.Rows
        Dim rbl As RadioButtonList = DirectCast(row.FindControl("rblDiff"), RadioButtonList)
        rbl.SelectedValue = selectedValue__1
    Next
End Sub

【问题讨论】:

  • 因此,如果您在标题“Easy”中选择,Gridview-column 中的所有项目都应该设为 Easy 吗?这是你的需要吗?
  • 是的,这就是我需要的......

标签: asp.net vb.net gridview radiobuttonlist


【解决方案1】:

试试这个,使用服务器端处理:

<asp:RadioButtonList  ID="rblDifficulty"  runat="server" AutoPostBack="true" OnSelectedIndexChanged="rblDifficulty_onChanged">
    <asp:ListItem Text="Easy" Value="0"></asp:ListItem>
    <asp:ListItem Text="Medium" Value="Y"></asp:ListItem>
    <asp:ListItem Text="Hard" Value="F"></asp:ListItem>
</asp:RadioButtonList>

protected void rblDifficulty_onChanged(object sender, EventArgs e)
{
    RadioButtonList rblDifficulty = (RadioButtonList)gvData.HeaderRow.FindControl("rblDifficulty");
    string selectedValue = rblDifficulty.SelectedValue;

    foreach (gvData row in gvData.Rows)
    {
        RadioButtonList rbl = (RadioButtonList)row.FindControl("rblDiff");
        rbl.SelectedValue = selectedvalue;
    }
}

未经测试,但肯定会给您提示如何操作。祝你好运! :)

【讨论】:

  • tq 我现在让它工作:受保护的 Sub rblDifficulty_onChanged(sender As Object, e As EventArgs) Dim rblDifficulty As RadioButtonList = DirectCast(gvData.HeaderRow.FindControl("rblDifficulty"), RadioButtonList) Dim selectedValue__1 As String = rblDifficulty.SelectedValue For Each row in gvData.Rows Dim rbl As RadioButtonList = DirectCast(row.FindControl("rblDiff"), RadioButtonList) rbl.SelectedValue = selectedValue__1 Next End Sub
  • 您可以编辑您的帖子并展示您对问题的解决方案。并请在您的帖子中添加 VB 作为标签。以后可能对其他人有很好的帮助。
猜你喜欢
  • 2010-11-13
  • 2011-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-14
  • 1970-01-01
  • 1970-01-01
  • 2021-05-11
相关资源
最近更新 更多