i am new to asp.net . i want to update a datagridview which is placed int updatepanel. i want to write some text in a TextBox and want to populate the datagridview just like a
"keyword search". on every TextChange Event i want to update the datagridview .
i dont know how to do that.
advance thanks for help provided.
mansoor.
Loading
Satyapriya NayakPosted Jan 2, 2012, 6:58 AM
After writing something in the textbox,move the cursor out of the textbox.
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
using System;
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;
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlDataAdapter ad = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter sqlda;
DataSet ds;
string str;
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
str = "select * from Contacts where name like '" + TextBox1.Text + "%'";
cmd = new SqlCommand(str, conn);
sqlda = new SqlDataAdapter(cmd);
ds = new DataSet();
sqlda.Fill(ds, "Contacts");
conn.Close();
GridView1.DataSource = ds;
GridView1.DataMember = "Contacts";
GridView1.DataBind();
}
}
Thanks
mansoor altafPosted Jan 2, 2012, 8:52 AM