Results 1 to 4 of 4

Thread: ASP.Net/C# - Gridview with dropdown list help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Location
    N.Ireland
    Posts
    71

    ASP.Net/C# - Gridview with dropdown list help

    Hi, I've a web page that contains a Customers DDL, and a ClassCode gridview with a Salesman DDL. So far i have manged to populate the Customers DDL as well as binding data to the ClassCode gridview/ Salesman DDL. My next step is depending on which customer is selected(code event below), query the DB to get all relevant ClassCodes/Salesmen and update the gridview and any instances where the classcode doesn't exist for the customer the Salesman DDL will have a default value. Here's my code so far:
    Code:
    protected void ddlCustomers_SelectedIndexChanged(object sender, EventArgs e)
            {
                BindData();
    
                DataTable dt = new DataTable();
                try
                {
                    con = new SqlConnection(strConnString);
                    SqlDataAdapter ad = new SqlDataAdapter("exec dbo.GetProductClsCodeAndSalesman '" + ddlCustomers.SelectedItem.Text + "'", con);
                    DataSet ds = new DataSet();
                    ad.Fill(ds, "ProductClsCodeAndSalesman");
    
                    for (int i = 0; i < gvProductClass.Rows.Count; i++)
                    {
                        //the logic to check each row and update the Salesman goes here    
                    }                
                }...
    can anyone help me to get the ClassCode for that row by getting DataKeys of the GridView, using the RowIndex of the Row. See if you have a SalesMan for the ClassCode.
    If you do, use FindControl to find the DropDownList in the Row, and set its SelectedValue.

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: ASP.Net/C# - Gridview with dropdown list help

    Hello,

    There are a number of ways that you can do this, for instance...

    Use AJAX:
    http://www.asp.net/ajaxLibrary/AjaxC...gDropDown.aspx

    Use Bindings:
    http://www.dotnetcurry.com/ShowArticle.aspx?ID=221

    Use jQuery:
    http://www.mikesdotnetting.com/Artic...ry-and-ASP.NET

    Hope that helps!

    Gary

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2010
    Location
    N.Ireland
    Posts
    71

    Re: ASP.Net/C# - Gridview with dropdown list help

    hi gep13, I can't see how using a cascading ddl would work because at the minute I have 1 stored procedure that fills the Salesman DDL(that is a col in the GV) with 8 values. But once a customer is selected from the Customers DDL (a new SP is executed) which reutrns ClassCode and Salesman for that customer. I want to cycle through each row on the gridview and update the Salesman value if the classcode/salesman exist for that customer else put a default value in the Salesman DDL. Hope this makes sense.

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: ASP.Net/C# - Gridview with dropdown list help

    Hello,

    This technique will definitely work, however, you may need to alter the structure of your calls to the database.

    Did you look at this example?

    http://www.asp.net/ajaxLibrary/AjaxC...CCDWithDB.aspx

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width