hi Friends,
i am having 4 dropdownlists in my web page...when i select first one releated data is foing to be displayed in second dropdown list... and i select 3rd dropdownlist releated data will be display in dropdownlist4....how to do this ....please help me
Loading
srikanthreddyPosted Feb 13, 2012, 5:10 AM
i have problem with dropdownlist 3 and dropdownlist 4....can u please tell me how to solve this problem...........
Suthish NairPosted Feb 13, 2012, 2:57 AM
khaleel shaikPosted Feb 13, 2012, 1:50 AM
Satyapriya NayakPosted Feb 13, 2012, 1:43 AM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Dropdownlist4._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 Dropdownlist4
{
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 id");
con.Open();
str = "select * from test";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
DropDownList1.Items.Add(reader["id"].ToString());
}
reader.Close();
con.Close();
}
DropDownList2.Items.Clear();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList1.AutoPostBack = true;
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from test where id='" + DropDownList1.SelectedItem.Text + "'";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
DropDownList2.Items.Add(reader["name"].ToString());
}
reader.Close();
con.Close();
}
}
}
Thanks
Krishna GaradPosted Feb 13, 2012, 1:31 AM