1

当我执行 aradiobuttonclick时,我想将 a 设置dropdownlist为可见。radiobuttondropdownlist都在同一个范围内datagrid。我不知道该怎么做。

<asp:UpdatePanel ID="updatepanel" UpdateMode="conditional" runat="server">
    <ContentTemplate>
        <asp:DataGrid ID="DataGrid" AutoGenerateColumns = "false" CssClass="objectSubTitle" ItemStyle-Wrap="true" runat="server" OnItemCommand="handler" ><Columns>
            <asp:TemplateColumn>
                <ItemTemplate>
                   <asp:RadioButton ID ="RadioButton1" Text="Yes" GroupName="creatingNewCard" OnCheckedChanged="RadioButtonYes" AutoPostBack="True" runat="server" />
                  <asp:DropDownList ID="DropDownList1"  Visible="false" runat="server"/>
                </ItemTemplate>
            </asp:TemplateColumn>
4

2 回答 2

2

假设它们在ItemTemplatea 中TemplateField,并且您想在服务器端切换生存能力:

protected void RbCheckedChanged(Object sender, EventArgs e)
{
    var radioButton1 = (RadioButton)sender;
    var row = (GridViewRow)radioButton1.NamingContainer;
    var dropDownList1 = (DropDownList)row.FindControl("DropDownList1");
    dropDownList1.Visible = radioButton1.Checked;
}

示例网格视图:

<asp:GridView ID="GridView1" AutoGenerateColumns="false" OnRowDataBound="Grid_RowDataBound"
    runat="server">
    <Columns>
    <asp:TemplateField>
        <ItemTemplate>
            <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
        <ItemTemplate>
            <asp:RadioButton  ID="RadioButton1" runat="server" OnCheckedChanged="RbCheckedChanged" AutoPostBack="true"></asp:RadioButton>
        </ItemTemplate>
    </asp:TemplateField>
    </Columns>
</asp:GridView>

编辑:当您编辑问题以表明您确实使用 aDataGrid而不是 aGridView时,代码类似:

protected void RbCheckedChanged(Object sender, EventArgs e)
{
    var radioButton1 = (RadioButton)sender;
    var item = (DataGridItem)radioButton1.NamingContainer;
    var dropDownList1 = (DropDownList)item.FindControl("DropDownList1");
    dropDownList1.Visible = radioButton1.Checked;
}
于 2012-07-18T20:04:55.673 回答
0

您可以像这样在单选按钮检查更改事件中调用 DropdwonList 的 Visible 属性

protected void RadioButton1_CheckedChanged(Object sender, EventArgs e)
{
    var radioButton1= (RadioButton)sender;
    var item = (DataGridItem)radioButton1.NamingContainer;
    var dropDownList1 = (DropDownList)item.FindControl("DropDownList1");

    dropDownList1.Visible = radioButton1.Checked ? true : false;
}
于 2012-07-18T20:20:55.273 回答