Displaying the Grid using AJAXtools

Posted by Sathiya_Narayanan under ASP.NET AJAX on 4/5/2013 | Points: 10 | Views : 949 | Status : [Member] | Replies : 1
Hi All.

Please guide me how to display the grid using ajax controls like if any character is entered in a textbox grid should display dynamically
according to entered text in textbox without using any search button or search option.(btn_search_Click(object sender, EventArgs e))

select * from test..tbl_Name WHERE Fname like 'sa%' this query to executed & table to displayed when i entered a text in textbox.

can anybody share your tips & examples.

SATHIYANARAYANAN


Responses

Posted by: Satyapriyanayak on: 4/5/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Textbox_gridview._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:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate >
<asp:Label ID="Label1" runat="server" Text="Type Empid " BackColor="#FFFF99"
ForeColor="Red" Width="100px"></asp:Label>
<asp:TextBox ID="txt_empid" runat="server" AutoPostBack ="true" ontextchanged="txt_empid_TextChanged"
></asp:TextBox>
</ContentTemplate>

</asp:UpdatePanel>
<br />

<asp:UpdatePanel ID="up2" runat="server">
<ContentTemplate >
<asp:Label ID="Label2" runat="server" Text="Corresponding Records" BackColor="#FFFF66"
ForeColor="Red" Width="100px"></asp:Label>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<br />
</div>
</form>
</body>
</html>



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Textbox_gridview
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindgrid();
}
}
public void bindgrid()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from employee";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "employee");
GridView1.DataMember = "employee";
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}

protected void txt_empid_TextChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from employee where empid like '" + txt_empid.Text + "%'";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "employee");
GridView1.DataMember = "employee";
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
}
}


If this post helps you mark it as answer
Thanks

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response