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;
public partial class Example : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DDLDataSource();
}
}
private void DDLDataSource()
{
string connString = "data source=SOFT14-PC;Initial Catalog=selvi;User ID=sa;Password=sa";
using (SqlConnection conn = new SqlConnection(connString))
{
string queryString = "SELECT * FROM Products";
SqlCommand comm = new SqlCommand(queryString, conn);
SqlDataAdapter da = new SqlDataAdapter(comm);
DataTable dt = new DataTable();
da.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "ProductName";
DropDownList1.DataValueField = "ProductID";
DropDownList1.DataBind();
}
}
private void FetchProductData()
{
string connString = "data source=SOFT14-PC;Initial Catalog=selvi;User ID=sa;Password=sa";
using (SqlConnection conn = new SqlConnection(connString))
{
string queryString = "SELECT * FROM Products WHERE ProductID=@ProductID";
SqlCommand comm = new SqlCommand(queryString, conn);
comm.Parameters.AddWithValue("ProductID", DropDownList1.SelectedItem.Value);
SqlDataAdapter da = new SqlDataAdapter(comm);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt != null && dt.Rows.Count > 0)
{
TextBox1.Text = dt.Rows[0]["ProductID"].ToString();
TextBox2.Text = dt.Rows[0]["ProductName"].ToString();
TextBox3.Text = dt.Rows[0]["ProductCategoryName"].ToString();
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex != -1)
{
FetchProductData();
}
}
}
Output
s g b
corect my codings wer i hav done mistake
Loading

SenthilkumarPosted Apr 19, 2012, 7:21 AM
Hope this will help you.
selvi subramanianPosted Apr 19, 2012, 7:23 AM
selvi subramanianPosted Apr 19, 2012, 7:07 AM
selvi subramanianPosted Apr 19, 2012, 6:58 AM
SenthilkumarPosted Apr 19, 2012, 4:25 AM
I debugged your code with the same database and table name. It is working fine and there are no errors.
I suggest you to check the few things.
Check1:
Make sure than you have enabled the auto post back property.
Check2:
Make sure that you have used the try catch block in your code
Always its better to put the break point and run your application, where it breaks.
Hope this will help you.