Dropdownlist populates Datagrid

Discussion in 'ASP .Net' started by =?Utf-8?B?Um9zZQ==?=, Aug 29, 2005.

  1. 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);
    }
     
    =?Utf-8?B?Um9zZQ==?=, Aug 29, 2005
    #1
    1. Advertising

  2. 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);
    }
     
    =?Utf-8?B?Um9zZQ==?=, Aug 29, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gk
    Replies:
    1
    Views:
    483
  2. =?Utf-8?B?a2VuIHM=?=

    javascript populates dropdownlist

    =?Utf-8?B?a2VuIHM=?=, Feb 10, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    381
    Ken Smith
    Feb 11, 2007
  3. John Grandy

    client-side onclick populates dropdown

    John Grandy, May 13, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    496
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=
    May 17, 2007
  4. Eric

    SQL Server BackEND Populates Datagrid with HTML Snipets

    Eric, Apr 2, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    145
  5. PetroTiburcio

    Populates GridView2 based on selected row from GridView1

    PetroTiburcio, Jun 7, 2013, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    460
    PetroTiburcio
    Jun 7, 2013
Loading...

Share This Page