ih ave one table called codemster in that table i have two fileds codetype and codedesc codetype is ...
ihave one table called codemaster in that table i have two fields code type and codedesc codetype is in drop down list and codedesc is in textbox both data type are varchar.when i select area in codetype all are displayed.i have antoher design customer registration in that area have one field is in dropdown list in that dropdown list codemaster table areas have to come in that dropwdown list how to do help me please
Satyapriya NayakPosted Jan 8, 2012, 8:51 AM
When you choose any codetype from the dropdownlist then its corresponding codedesc will be shown in the textbox.
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 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 codetype");
con.Open();
str = "select * from codemaster";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
DropDownList1.Items.Add(reader["codetype"].ToString());
}
reader.Close();
con.Close();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from codemaster where codetype='" + DropDownList1.SelectedItem.Text + "'";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
TextBox1.Text = reader["codedesc"].ToString();
}
reader.Close();
con.Close();
}
}
Thanks