Tuesday, 3 January 2012

Front End for taking input from textbox and button to press


<%@ 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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Height="26px" onclick="Button1_Click"
            Text="Button" />
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
   
    </div>
    </form>
</body>
</html>


//Back End in Button Click Event

protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection scon = new SqlConnection("database=Tahir_Khalid;trusted_connection=yes");
        SqlCommand scmd = new SqlCommand("select * from Tahir where RollNo=@rollno", scon);
        scmd.Parameters.Add("rollno", SqlDbType.Int).Value = TextBox1.Text;
        SqlDataAdapter sda = new SqlDataAdapter(scmd);
        DataSet ds = new DataSet();
        sda.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }




No comments:

Post a Comment