Reputation: 157
I have a gridview with 3 columns: State(bound field), Code (bound field) and ChangeCode (dropdown). The purpose of the ChangeCode field is to change the value of the Code for a particular state. The list of Codes applicable to each state are different.
I have a table with a list of states and their current codes. I have one more table with a list of permissible codes for each state. I want the change code dropdown to dynamically display all permissible codes applicable for the current record. I am using ASP.NET with C#.
The State and Code fields are fetched from one datasource. I am unable to fetch the ChangeCode dropdown values from a different datasource with the query containing the current record's State value. This is because I'm unable to parse the current gridview's row at runtime. Any ideas on how to implement this would be much appreciated....
Upvotes: 0
Views: 4007
Reputation: 1391
you can use RowDataBound event of Gridview and bind ChangeCode dropdown for particular state in this event.
void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
DataRowView drv = (DataRowView)e.Row.DataItem;
if(e.Row.RowType == DataControlRowType.DataRow)
{
String State = drv["StateColumnName"].ToString();
//Now You Have State So You Can Get All Code Values By State Name
DataTable dtcodes = GetByState();
//Now Bind This Code To DropDownList Of Codes
DropDownList dropdownCodes = (DropDownList)e.Row.FindControl("dropdownCodes");
dropdownCodes.DataSource = dtcodes;
dropdownCodes.DataBind();
}
}
Upvotes: 0