my table contains
| ID | waName | waProID | Date | Allocater |
| 6 | 11 | DU/0005 | 3/15/2012 | Administrator |
| 7 | 11 | DU/0006 | 3/28/2012 | Administrator |
and in my aspx page contains
dropdowns[ddlwaProID] if i select from this record in TextBox i want to display Allocater Name..
can any one suggest me?just want to display in Text Box..
wat i have to do..i have to create sp?or only query s enough?
thanks and regards..

Satyapriya NayakPosted Mar 22, 2012, 5:55 AM
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Dropdownlist_Default" %>
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
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.AutoPostBack = true;
SqlConnection con = new SqlConnection(strConnString);
if (!IsPostBack)
{
DropDownList1.Items.Add("Choose waProID");
con.Open();
str = "select * from test";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
DropDownList1.Items.Add(reader["waProID"].ToString());
}
reader.Close();
con.Close();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from test where waProID='" + DropDownList1.SelectedItem.Text + "'";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
TextBox1.Text = reader["Allocater"].ToString();
}
reader.Close();
con.Close();
}
}
}
Thanks
Suthish NairPosted Mar 22, 2012, 10:51 AM
fahad sheikhjiPosted Mar 22, 2012, 8:11 AM
fahad sheikhjiPosted Mar 22, 2012, 5:14 AM
Meera MohiddinPosted Mar 22, 2012, 4:48 AM
Just simple query is enough.
Try this one.
in code behind:
int l_iValue=convert.toint32(dropdownlist1.selectedvalue.tostring())
dataset l_ds=new dataset();
sqlconnection con=new sqlconnection("");
sqldataadapter da=new sqldataadapter("select allocater from tablename where id="+l_ivalue)
da.fill(ds);
if(ds.tables[0].rows.count>0)
{
textbox1.text=ds.tables[0].rows[0]["columnname"].tostring();
}