how to bind value in dropDownList

Posted by Gow.net under ASP.NET on 2/13/2012 | Points: 10 | Views : 2622 | Status : [Member] | Replies : 8
hi any one tell me
in my application i have two DropDownList

In DropDownList1 I add Only one item,i Select that item means Based on that selected item bind items in data base in DropDownList22 please tell me any one how write code for this

gowthaman8870226416


Responses

Posted by: Nishantcomp2512 on: 2/13/2012 [Member] Starter | Points: 25

Up
0
Down
you can create a onchange event or means on selected item change event for 1st dropdown and accoriding to it change the another one.

Gow.net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gow.net on: 2/13/2012 [Member] Starter | Points: 25

Up
0
Down
sir please give me example code


gowthaman8870226416

Gow.net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 2/13/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Check this link
http://forums.asp.net/t/793752.aspx/1

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Gow.net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 2/13/2012 [Member] Silver | Points: 25

Up
0
Down

Hi, you can call fill method of dropdownlist1 in page_load.
Since you have only one item to be bound in dropdownlist, add a default value like -Choose- or -Select- whose value field will be 0.
so that you can select an item.
Now on selected index changed ivent you can call the dropdownlist2 fill method.

Thanks,
Sanjay

Gow.net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nvm on: 2/13/2012 [Member] Starter | Points: 25

Up
0
Down


Hi ,

have try this Link
http://forums.asp.net/p/1537443/3739323.aspx

Thanks
NVM

Gow.net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/24/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

check this url

http://www.dotnetfunda.com/codes/code3246-how-to-load-dropdown-list-in-selected-event-bind-the-data-from-db.aspx

Mark as Answer if its helpful to you

Gow.net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kianurieves on: 9/25/2012 [Member] Starter | Points: 25

Up
0
Down
You might want to do something like the code below. You can not set the "SelectedValue" declaratively, but by saying "SelectedValue=<%# [code here] %> you are effectively causing the value to be set when the control is data bound.
http://www.dapfor.com/en/net-suite/net-grid/tutorial/headers-and-columns


Gow.net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 1/24/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
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();
}
}
}


If this post helps you mark it as answer
Thanks

Gow.net, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response