Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Dropdownlist populates Datagrid

Reply
Thread Tools

Dropdownlist populates Datagrid

 
 
=?Utf-8?B?Um9zZQ==?=
Guest
Posts: n/a
 
      08-29-2005
Hi, I'm new to asp.net and c#, so this is probably an easy question for
everybody.

I want to have a dropdownlist (populated by states), when the user selects a
different value, populate a datagrid based on the dropdownlist's value.

I'm not quite sure what I'm missing here. Please advise.

THANKS!


Here's my code:

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
BindData("WHERE StateCode = 'CA' ");
}
} //page load

private void BindData( string strState)
{
fillStates();
getAbbreviations( strState );
}

private void fillStatees()
{
sqlDataAdapter1.Fill(dsStates1);
DataTable dataTable = dsStates1.Tables[0];
ddListState.DataTextField = dataTable.Columns["StateName"].ToString();
ddListState.DataValueField = dataTable.Columns["StateCode"].ToString();
ddListState.DataBind();
}

private void getAbbreviations( string strState )
{
string conn = "Data Source=myServer;Initial Catalog=myDB;Integrated
Security=SSPI;";

string cmd;

cmd = cmd + "SELECT ID, Name from Client ";

SqlDataAdapter dataAdapter = new SqlDataAdapter( cmd, conn );
DataSet dataSet = new DataSet();

dataAdapter.Fill(dataSet);
DataTable dataTable = dataSet.Tables[0];

dAbbreviations.DataSource = dataTable;
dAbbreviations.DataBind();
}

private void ddListState_SelectedIndexChanged(object sender,
System.EventArgs e)
{
string strState = "WHERE StateCode = '" +
ddListState.SelectedItem.Value + "' ";
BindData(strState);
}


 
Reply With Quote
 
 
 
 
=?Utf-8?B?Um9zZQ==?=
Guest
Posts: n/a
 
      08-29-2005
Sorry, I edited my code too quickly... this is the correct code.

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
BindData("WHERE StateCode = 'CA' ");
}
} //page load

private void BindData( string strState)
{
fillStates();
getAbbreviations( strState );
}

private void fillStates()
{
sqlDataAdapter1.Fill(dsStates1);
DataTable dataTable = dsStates1.Tables[0];
ddListState.DataTextField = dataTable.Columns["StateName"].ToString();
ddListState.DataValueField = dataTable.Columns["StateCode"].ToString();
ddListState.DataBind();
}

private void getAbbreviations( string strState )
{
string conn = "Data Source=myServer;Initial Catalog=myDB;Integrated
Security=SSPI;";

string cmd;

cmd = "SELECT ID, Name ";
cmd = cmd + "FROM Client ";
cmd = cmd + strBranch;
cmd = cmd + "ORDER BY Name;";

SqlDataAdapter dataAdapter = new SqlDataAdapter( cmd, conn );
DataSet dataSet = new DataSet();

dataAdapter.Fill(dataSet);
DataTable dataTable = dataSet.Tables[0];

dAbbreviations.DataSource = dataTable;
dAbbreviations.DataBind();
}

private void ddListState_SelectedIndexChanged(object sender,
System.EventArgs e)
{
string strState = "WHERE StateCode = '" +
ddListState.SelectedItem.Value + "' ";
BindData(strState);
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
client-side onclick populates dropdown John Grandy ASP .Net 5 05-17-2007 04:19 AM
javascript populates dropdownlist =?Utf-8?B?a2VuIHM=?= ASP .Net 2 02-11-2007 03:04 AM
does DynaActionForm populates the text field of the JSP page ? gk Java 1 03-06-2006 06:50 AM
OE 6 Address Book Intact But No Longer Populates My Contact List in Left Window Pane geermeister@gmail.com Computer Support 4 09-25-2005 06:56 PM
SQL Server BackEND Populates Datagrid with HTML Snipets Eric ASP .Net Datagrid Control 2 04-05-2004 06:58 AM



Advertisments