Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<form id="form1" runat="server">
    <div>

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            onselectedindexchanged="GridView1_SelectedIndexChanged">
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="MethodOfPayment" HeaderText="Method of Payment"
                    SortExpression="MethodOfPayment" />
            </Columns>
        </asp:GridView>
        <br />
        <br />
        <asp:Label ID="Label1" runat="server" Text="Method of Payment:"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"
            ontextchanged="TextBox1_TextChanged"></asp:TextBox>
        <br />
        <asp:Label ID="Label2" runat="server" Text="Installment Amount:"></asp:Label>
        <asp:TextBox ID="TextBox2" runat="server" ontextchanged="TextBox2_TextChanged"></asp:TextBox>

    </div>
    </form>


I have this on my web page. Here are the codes inside.

protected void Page_Load(object sender, EventArgs e)
   {
       if (!Page.IsPostBack)
       {
           SqlConnection cn = new SqlConnection("Connection");
           cn.Open();

           string strSQL;

           strSQL = "SELECT * FROM Orders";

           SqlDataAdapter da = new SqlDataAdapter(strSQL, cn);

           DataSet ds = new DataSet();

           da.Fill(ds, "DB");

           GridView1.DataSource = ds;
           GridView1.DataBind();

           cn.Close();
       }
           Label2.Visible = false;
           TextBox2.Visible = false;

   }
   protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
   {
       TextBox1.Text = GridView1.SelectedRow.Cells[1].Text;
   }
   protected void TextBox1_TextChanged(object sender, EventArgs e)
   {
       if (TextBox1.Text == "Installment")
       {
           Label2.Visible = true;
           TextBox2.Visible = true;
       }
   }


Textbox2 and label2 are supposed to show if the value of the textbox1 is 'Installment'. What did I do wrong? Thank you!
Posted

1 solution

do like this...

C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            SqlConnection cn = new SqlConnection("Connection");
            cn.Open(); 
            string strSQL; 
            strSQL = "SELECT * FROM Orders"; 
            SqlDataAdapter da = new SqlDataAdapter(strSQL, cn); 
            DataSet ds = new DataSet(); 
            da.Fill(ds, "DB"); 
            GridView1.DataSource = ds;
            GridView1.DataBind();  
            cn.Close();
            Label2.Visible = false;
            TextBox2.Visible = false;
        } 
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        TextBox1.Text = GridView1.SelectedRow.Cells[1].Text;
        if (TextBox1.Text == "Installment")
        {
            Label2.Visible = true;
            TextBox2.Visible = true;
        }
    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
       
    }


Or
   protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        TextBox1.Text = GridView1.SelectedRow.Cells[1].Text;
        TextBox1_TextChanged(sender, e);
    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        if (TextBox1.Text == "Installment")
        {
            Label2.Visible = true;
            TextBox2.Visible = true;
        } 
    }
 
Share this answer
 
v3
Comments
BeastMode10 19-Feb-14 8:12am    
thank you good sir! It worked! Thank you for your help!
OPees 19-Feb-14 22:59pm    
:) Welcome..!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900