关于详情查看
当我编写这样的代码时:
<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”时,我添加单击插入 ,两个单选按钮都是可见的。为什么?
When I write code like this:
<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>
And then in .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;
}
}
When Home is '2', I Add click to insert , both of the radiobuttons are visible.Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用详细信息视图数据绑定事件,而不是在页面加载中执行此操作,请尝试此代码...它肯定会工作
you need to use detailsview Databound event rather you are doing in page load, try this code... it will definitly work