当我写这样的代码时:
<asp:DetailsView ID="DetailsView1" Runat="server" DataSourceID="Vote" DefaultMode="Insert"
AutoGenerateRows="False" DataKeyNames="id" Width="352px" Height="50px"
HorizontalAlign="Left" >
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButton ID="RadioButtonVote" runat="server" Text="111"
GroupName="A" /><br/>
<asp:RadioButton ID="RadioButtonName" runat="server" Text="222"
GroupName="A"/>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField CancelText="取消" InsertText="添加" ShowInsertButton="True" ShowCancelButton="False"></asp:CommandField>
</asp:DetailsView>
然后在 .aspx.cs 中:
private string Home
{
get
{
if (Request.QueryString["home"] != null)
{
return Request.QueryString["home"].ToString();
}
return "1";
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindDatailsView();
}
}
private void BindDatailsView()
{
RadioButton radioButtonVote = this.DetailsView1.FindControl("RadioButtonVote") as RadioButton;
RadioButton radioButtonName = this.DetailsView1.FindControl("RadioButtonName") as RadioButton;
if (Home.Equals("1"))
{
radioButtonName.Visible = true;
radioButtonVote.Visible = true;
}
else if (Home.Equals("2"))
{
radioButtonVote.Visible = true;
radioButtonName.Visible = false;
}
}
当 Home 为“2”时,我添加 click to insert ,两个单选按钮都可见。为什么?