如何隐藏或单击编辑按钮时,基于另外两个文本框的条件禁用单选按钮列表和文本框 [英] How to hide or disable radiobuttonlist and textbox based on condition of another two textboxes when edit button is clicked

查看:229
本文介绍了如何隐藏或单击编辑按钮时,基于另外两个文本框的条件禁用单选按钮列表和文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有顺序文本框和单选按钮列表和编辑按钮,一个FormView如下:

I have a formview with textboxes and radiobuttonlist and edit button in the order as follows

 <asp:textbox id="tb1" runat="server" text='<%# Bind("DATE_1", "{0:d}") %>' />
 <asp:calendarextender id="tb1_CalendarExtender" runat="server" targetcontrolid="tb1" />

 <asp:textbox id="tb2" runat="server" text='<%# Bind("DATE_2", "{0:d}") %>' />
 <asp:calendarextender id="tb2_CalendarExtender" runat="server" targetcontrolid="tb2" />

 <asp:button id="EditButton" runat="server" causesvalidation="False" commandname="Edit" text="Edit" enabled='<%# CanEdit(Eval("DATE_1"), Eval("DATE_2")) %>' OnClick="EditButton_Click" />

 <asp:radiobuttonlist id="rbl1" runat="server" repeatdirection="Horizontal" text='<%# Bind("DIAG_LL_APPROVAL") %>'>
      <asp:ListItem>Approved</asp:ListItem>
      <asp:ListItem>Rejected</asp:ListItem>
      <asp:ListItem Selected="True">None</asp:ListItem>
 </asp:radiobuttonlist>
 <asp:textbox id="tb3" runat="server" text='<%# Bind("COMMENTS") %>' maxlength="1000"/>                                 

需要隐藏或关闭 RBL1 TB3 如果 TB1 TB2 没有任何价值(即)当编辑按钮被点击

Need to hide or disable rbl1 and tb3 if tb1 or tb2 doesn't have any value (i.e null) when edit button is clicked.

protected void EditButton_Click(object sender, EventArgs e)
    {
        TextBox t1 = FormViewName.FindControl("tb1") as TextBox;
        TextBox t2 = FormViewName.FindControl("tb2") as TextBox;
        RadioButtonList rbl = FormViewName.FindControl("rbl1") as RadioButtonList;
        TextBox t3 = FormViewName.FindControl("tb3") as TextBox;

        //if ("".Equals(tdcd) || "".Equals(tdrcd))
        if (!string.IsNullOrEmpty(t1.Text) && !string.IsNullOrEmpty(t2.Text))
        {
            FormViewName.FindControl("rbl1").Visible = true;
            FormViewName.FindControl("tb3").Visible = true;
        }
        else
        {
            FormViewName.FindControl("rbl1").Visible = false;
            FormViewName.FindControl("tb3").Visible = false;
        }
    }                                                                             

错误:Oject引用不设置到对象的实例

Error: Oject reference not set to an instance of an object

推荐答案

试试这个:
在编辑按钮点击事件:

Try this one: On Edit button click event:

if (string.IsNullOrEmpty(tb1.Text) && string.IsNullOrEmpty(tb2.Text))
        {
            rbl1.Visible = false;
            tb3.Visible = false;
        }

修改

TextBox txt = (TextBox)FormView1.FindControl("tb1");

TextBox txt1 = (TextBox)FormView1.FindControl("tb2");

TextBox tb3= (TextBox)FormView1.FindControl("tb3");

 RadioButtonList rb1= (RadioButtonList)FormView1.FindControl("rbl1");


    if (string.IsNullOrEmpty(txt.Text) && string.IsNullOrEmpty(txt1.Text))
            {
                rb1.Visible = false;
                tb3.Visible = false;
            }
          else

              {
                rb1.Visible = true;
                tb3.Visible = true;
}

这篇关于如何隐藏或单击编辑按钮时,基于另外两个文本框的条件禁用单选按钮列表和文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆