当我执行radiobuttonclick
时,我想将dropdownlist
设置为可见。 radiobutton
和dropdownlist
位于同一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>
答案 0 :(得分:2)
假设它们位于ItemTemplate
的{{1}},并且您希望在服务器端切换活动:
TemplateField
采样的GridView:
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>
而不是DataGrid
,因此代码类似:
GridView
答案 1 :(得分: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;
}