需要帮助根据 HeaderTemplate 中的选定值单选按钮列表为 ItemTemplate 中的 gridview 中的单选按钮列表设置相同的值
Need help setting the same values for radiobutton list in gridview in ItemTemplate based on selected value radiobuttion list in HeaderTemplate
我的任务是创建一个 Gridview,其中用户单击 header (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
试试这个,使用服务器端处理:
<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;
}
}
未测试,但肯定会提示您如何操作。祝你好运! :)
我的任务是创建一个 Gridview,其中用户单击 header (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
试试这个,使用服务器端处理:
<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;
}
}
未测试,但肯定会提示您如何操作。祝你好运! :)