Display Record in Textbox at the time of Page Load

Sandeepraturi
Posted by Sandeepraturi under ASP.NET category on | Points: 40 | Views : 1279
--------------database field------------
table name:example

id=int(auto increment,primary key)
name=varchar(50)
adddress=varchar(50)
email=varchar(50)


----------------put this code in body part-------------------

<body>
<form id="form1" runat="server">
<div>
<table align="center">
<tr><td colspan="2" align="center"><h1>Information</h1></td></tr>
<tr><td>Name:</td><td><asp:TextBox ID="name" runat="server" Enabled="false"></asp:TextBox></td></tr>


<tr><td>Address:</td><td><asp:TextBox ID="address" runat="server" TextMode="MultiLine" Enabled="false"></asp:TextBox></td></tr>

<tr><td>Email:</td><td><asp:TextBox ID="email" runat="server" Enabled="false"></asp:TextBox></td></tr>


</table>
</div>
</form>
</body>

-------------c# code--------------------

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;

namespace sandeep
{
public partial class showvalue : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("server=SANDEEP-PC;database=data;integrated security=true");
protected void Page_Load(object sender, EventArgs e)
{
SqlDataAdapter dap = new SqlDataAdapter("select * from example",con);
DataSet ds = new DataSet();
dap.Fill(ds);
name.Text=ds.Tables[0].Rows[0][1].ToString();
address.Text = ds.Tables[0].Rows[0][2].ToString();
email.Text = ds.Tables[0].Rows[0][3].ToString();

}
}
}

Comments or Responses

Login to post response