关于详情查看

发布于 2024-08-12 05:28:56 字数 1770 浏览 3 评论 0原文

当我编写这样的代码时:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坠似风落 2024-08-19 05:28:56

您需要使用详细信息视图数据绑定事件,而不是在页面加载中执行此操作,请尝试此代码...它肯定会工作

 protected void DetailsView1_DataBound(object sender, EventArgs e)
{
    if (DetailsView1.CurrentMode == DetailsViewMode.Insert)
    {
        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;
        }
    }
}

you need to use detailsview Databound event rather you are doing in page load, try this code... it will definitly work

 protected void DetailsView1_DataBound(object sender, EventArgs e)
{
    if (DetailsView1.CurrentMode == DetailsViewMode.Insert)
    {
        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;
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文