Hi All,
i want to have a one gridview where i can type key word in one textbox and when textchange it should automatically retrive the related data from the database and complete the row in gridview.likewise i should be able to add items one by one to the gridview.
Is is possible to have a this kinda gridview ? can anybody give me some sample code snippet or a link please.
Thanks,
Max
Loading
Satyapriya NayakPosted Apr 6, 2012, 8:31 AM
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
If this post helps you mark it as answer