Tuesday 5 November 2013

How to Increase and decrease the size of text box during runtime

Default.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
            <center>
            <table width="50%">
                <tr>

                    <td>
                         
                        <asp:TextBox ID="TextBox1" runat="server" style="line-height:30px" Width="500px" TextMode="MultiLine" 
                            Height="270px"  BackColor="#F3F3F3" BorderStyle="None" Font-Names="Verdana"></asp:TextBox>
                             
                    </td>
                </tr>
                 <tr> 
                    <td>
                    <br />
                        <asp:TextBox ID="TextBox2" runat="server" style="line-height:30px" Width="500px" TextMode="MultiLine" 
                            Height="90px"  BackColor="#F3F3F3" BorderStyle="None" Font-Names="Verdana"></asp:TextBox>
                             
                    </td>
                </tr>
                <tr>
                    <td align="center"><br />
                        <asp:Button ID="Button1" Width="80px" Height="30" runat="server" Text="Update" 
                            onclick="Button1_Click" />
                        
                            <br /><br />
                    </td>
                </tr>
            </table>
        </center>
    </div>
    </form>
</body>
</html>


Default.aspx.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
     SqlConnection con = new SqlConnection("Data Source=TARUNKUMAR-PC\\SA;Initial Catalog=pops;Integrated Security=True");
    SqlDataAdapter da;
    SqlCommand cmd;
    DataTable dt;
    protected void Page_Load(object sender, EventArgs e)
    {
         if (!IsPostBack)
        {
            details();
        }
    }
 
 
   
    
    public void details()
    {
        da = new SqlDataAdapter("select Details,Email  from ContactEntry where Id=1", con);
        dt = new DataTable();
        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {
           
            TextBox1.Text = dt.Rows[0][0].ToString();
          
            TextBox2.Text = dt.Rows[0][1].ToString();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        string[] lines = this.TextBox1.Text.Split(new Char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
        int count = lines.Length;

        cmd = new SqlCommand("update ContactEntry set Details=@Details,Email=@Email,line=@line where Id=1", con);

        cmd.Parameters.AddWithValue("@Details", TextBox1.Text);
        cmd.Parameters.AddWithValue("@Email", TextBox2.Text);
        cmd.Parameters.AddWithValue("@line", Convert.ToInt16(count));
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
    }
}

//Output of this page is


// this page we only Fill the Details  and update this details in database . when we update then No.
//of rows are counted and updated in database.




//Now On The Second Page we will get the Details from data base and show it in a textbox with //Only  4 rows size

Default2.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <center>
            
            <dl>
                        <asp:TextBox ID="TextBox1" runat="server" style="line-height:30px" Width="500px" Font-Size="15px" TextMode="MultiLine" 
                            Height="270px" ReadOnly="true"   BackColor="#F3F3F3" BorderStyle="None" Font-Names="Verdana"></asp:TextBox>
                             

                            <asp:TextBox ID="TextBox2" runat="server" ForeColor="Blue" style="line-height:30px" Width="500px" TextMode="MultiLine" 
                            Height="90px"  BackColor="#F3F3F3" BorderStyle="None" Font-Names="Verdana"></asp:TextBox>
                            </dl>
            
        </center>
    </div>
    </form>
</body>
</html>


Default2.aspx.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data Source=TARUNKUMAR-PC\\SA;Initial Catalog=pops;Integrated Security=True");
    SqlDataAdapter da;
    SqlCommand cmd;
    DataTable dt;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            details();
        }
    }
    public void details()
    {
        da = new SqlDataAdapter("select Details,Email,line from ContactEntry where Id=1", con);
        dt = new DataTable();
        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            int heights = Convert.ToInt32(dt.Rows[0][2].ToString());
            int hh = heights * 30;
            TextBox1.Height = hh;

            TextBox1.Text = dt.Rows[0][0].ToString();
            //int sss=dt.Rows[0][0].ToString().Length;
            TextBox2.Text = dt.Rows[0][1].ToString();
        }
    }
}


//Output of this page is



No comments:

Post a Comment