Hi,
i gave a gridview with textbox in first row and first column after entering one data in thid textbox corresponding data should fetch from DB and display 2nd and 3ed column of first row. next if i enter data in 2nd row and first column textbox the corresponding data should fetch from DB and display in 2nd and 3ed column of 2nd row and so on. how to do this. Here my problem is how to mention textbox inside the gridview while writing query mainly in where condition.
like select * from employee where id='"+textbox1.text+"'
here i used textbox inside the grid, in this condition how to mention textbox under where condition. please can anyone help me? it's very urgent please.
Loading
AshwiniPosted Oct 31, 2011, 12:47 AM
Thanks for your replay it's working fine. But in gridview only 2 rows are displaying but i need to put 5 rows, why what's the problem please let me know.
AshwiniPosted Oct 31, 2011, 12:29 AM
your code is working but it's displaying only two rows is gridview, i need to put 5 rows how to do this one. And one more i entered values in first textbox corresponding values will display, if enter in 2nd row first row data will disappear 2nd row data will show. i need all the row should show the data in gridview. please let me know how to do this.
Prabhu RajaPosted Oct 30, 2011, 10:59 AM
I attached Source code Here. Hope it will be useful for you.
V S N Raju KanumuriPosted Oct 30, 2011, 7:47 AM
protected void txt_TextChanged(object sender, System.EventArgs e)
{
TextBox txt = sender as TextBox;
foreach (GridViewRow row in grd.Rows)
{
Control ctrl = row.FindControl("txt") as TextBox;
if (ctrl != null)
{
TextBox txtid = (TextBox)ctrl;
if (txt.ClientID == txtid.ClientID)
{
TextBox txt1 = row.FindControl("txt1") as TextBox;
TextBox txt2 = row.FindControl("txt2") as TextBox;
SqlConnection con = new SqlConnection("data source=hobvision07; initial catalog=MBOMexcel; user id=sa; password=hobvision");
SqlCommand cmd = new SqlCommand("select * from sampledata where productid='" + txt.Text + "'", con);
SqlDataAdapter sqlda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sqlda.Fill(dt);
txt1.Text=dt.Rows[0][1].ToString();
txt2.Text=dt.Rows[0][1].ToString();
}
}
}
}
Bind values to gridview in page load Then only it display the textboxes.
I am not mentioned autocomplete extender in above code
AshwiniPosted Oct 29, 2011, 8:59 AM
i have done according to your suggestion but its not displaying in gridview please see what's the problem.
my .aspx code is
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="dbauto.aspx.cs" Inherits="Default4" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" tagprefix="cc1"%>
.aspx.cs code is
using System;
using System.Configuration;
using System.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlClient;
public partial class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List
l.Add("Row 1");
l.Add("Row 2");
grd.DataSource = l;
grd.DataBind();
}
}
protected void txt_TextChanged(object sender, System.EventArgs e)
{
SqlConnection con = new SqlConnection("data source=hobvision07; initial catalog=MBOMexcel; user id=sa; password=hobvision");
SqlCommand cmd = new SqlCommand("select * from sampledata where productid='" + txt.Text + "'", con);
SqlDataAdapter sqlda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sqlda.Fill(dt);
grd.DataSource = dt;
grd.DataBind();
}
}
my webservice.asmx code is
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
///
/// Summary description for WebService
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
public WebService()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] GetCompletionList(string prefixText)
{
SqlConnection con = new SqlConnection("data source=hobvision07; initial catalog=MBOMexcel; user id=sa; password=hobvision");
SqlDataAdapter dad = new SqlDataAdapter("select * from sampledata where productid like '" + prefixText + "%'", con);
DataSet ds = new DataSet();
dad.Fill(ds);
string[] list = new string[ds.Tables[0].Rows.Count];
int i = 0;
foreach (DataRow dr in ds.Tables[0].Rows)
{
list.SetValue(dr[0].ToString(), i);
i++;
}
return list;
}
}
please help me.
V S N Raju KanumuriPosted Oct 29, 2011, 8:15 AM
Writ code inside the textchanged event(like select * from employee where id='"+textbox1.text+"')
V S N Raju KanumuriPosted Oct 29, 2011, 7:39 AM
Use autocomplete extender to the textbox. Autocomplete Extender is an ajax control. so, place that extender in the gridview edit item template .
I think this is useful to you.