Hi,
i am developing a application in which iam using dropdown list,textbox controls in gridview. in the gridview first column(product id) i am placing dropdown list i.e all the rows of first column having dropdown list. in gridview 2nd and 3ed(name and address) column i am placing textboxes i.e in all the rows of column 2nd and 3ed. i am having table in database like address which is having column names as produci id, name, address. now what i wanted to do is i wil display all the product id's in all the dropdown list of gridview. after this user will select product id from gridview 1st row dropdown list, the corresponging values of product id should fetch from DB and display it 2nd and 3ed column of 1st row in gridview. like this same thing for 2nd row and so on. how to do this i am not getting. please can any body help me. Thanks in advance.
Loading
TulasiPosted Oct 25, 2011, 3:34 AM
source code
Please mark the answer as Accepted if it helps you.
AshwiniPosted Nov 4, 2011, 12:04 AM
Thanks for your kind replay, not to worry i have solved that problem.
TulasiPosted Nov 3, 2011, 5:56 AM
could u tel me where ur getting problem ? i mean getting seleted id of autocomplete extender or placing content in selected gridview . so that i can help u
AshwiniPosted Oct 29, 2011, 12:12 AM
i wanted to fetch values from DB after selecting one value from autocomplete extender the corresponding values should fetch and display in gridview row. please help me its not working for me.
TulasiPosted Oct 27, 2011, 1:29 AM
chk this
http://blogs.msdn.com/b/phaniraj/archive/2007/06/19/how-to-use-a-key-value-pair-in-your-autocompleteextender.aspx
AshwiniPosted Oct 25, 2011, 7:51 AM
Thanks for your replay it's working. But what i want is the user will select one id in textbox of autocomplete extender in first row and first column of gridview after selection corresponding name and address should display in column 2 and 3 of first row of gridview. if he select id from 2nd row the corresponding details should come and display in 2nd and 3ed column of 2nd row. how to do giveme some idea.
Really thanks for you i am new to ajax controls.
AshwiniPosted Oct 25, 2011, 1:35 AM
It's working fine, now what i wanted to do is, i wil replace dropdownlist with textbox with autocomplete extender. is it possible to do it, please give me some ideas.
Satyapriya NayakPosted Oct 23, 2011, 10:26 AM
Here is your solution.Run the attachments.
<%@ 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 sqlda = new SqlDataAdapter();
SqlCommand com = new SqlCommand();
DataTable dt;
string str;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindgrid();
}
}
private void bindgrid()
{
SqlConnection conn = new SqlConnection(connStr);
dt = new DataTable();
com.Connection = conn;
com.CommandText = "SELECT * FROM Employees";
sqlda = new SqlDataAdapter(com);
sqlda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Control ctrl = e.Row.FindControl("ddlTest");
if (ctrl != null)
{
DropDownList dd = ctrl as DropDownList;
SqlConnection conn = new SqlConnection(connStr);
dt = new DataTable();
com.Connection = conn;
com.CommandText = "SELECT * FROM Employees";
sqlda = new SqlDataAdapter(com);
sqlda.Fill(dt);
dd.DataTextField = "EmployeeID";
dd.DataValueField = "EmployeeID";
dd.DataSource = dt;
dd.DataBind();
}
}
}
protected void ddlTest_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl = sender as DropDownList;
foreach (GridViewRow row in GridView1.Rows)
{
Control ctrl = row.FindControl("ddlTest") as DropDownList;
if (ctrl != null)
{
DropDownList ddl1 = (DropDownList)ctrl;
if (ddl.ClientID == ddl1.ClientID)
{
TextBox txt1 = row.FindControl("txt1") as TextBox;
TextBox txt2 = row.FindControl("txt2") as TextBox;
TextBox txt3 = row.FindControl("txt3") as TextBox;
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
str = "select * from Employees where EmployeeID='" + ddl1.SelectedItem.Text + "'";
com = new SqlCommand(str, conn);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
txt1.Text = reader["FirstName"].ToString();
txt2.Text = reader["LastName"].ToString();
txt3.Text = reader["Address"].ToString();
}
reader.Close();
conn.Close();
}
}
}
}
}
Thanks
If this post helps you mark it as answer