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.
Re: ASP.Net/C# - Gridview with dropdown list help
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.
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