Introduction
In this Artcile i will show you how can we change the value of one column on change of other column in gridview.
Using the code
I am using a gridview to show records. In two columns of gridview value will be show in dropdownlists. so on change of one dropdownlist value i have to change another dropdownlist's value.
I have two column One is 'project' and second is 'module'. so i want to show modules according to value of project.
I want to perform these action in edit mode of gridview.
Step 1: in gridview add two template fields. then add dropdownlists to EditItemtemplate of Template fields. Shown as below:
Step 2: We want modules name according to project name so we will set the autopostback property true for project dropdownlist.
step 3: Now double click on project dropdownlist for generate the selectedechanged event of dropdonlist.
protected void ddlProject_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
DropDownList ddlProject = (DropDownList)sender;
GridViewRow row = (GridViewRow)ddlProject.NamingContainer;
ddlProject = (DropDownList)GridView1.Rows[row.RowIndex].FindControl("ddlProject");
DropDownList ddlModule = new DropDownList();
ddlModule = (DropDownList)GridView1.Rows[row.RowIndex].FindControl("ddlModule");
int iProjectID = Convert.ToInt32(ddlProject.SelectedValue);
modulecl_ba omodule = new modulecl_ba();
DataTable dtmodule = new DataTable();
dtmodule = omodule.getModuleName(iProjectID);
ddlModule.DataTextField = "v_module_name";
ddlModule.DataValueField = "in_module_id";
ddlModule.DataSource = dtmodule;
ddlModule.DataBind();
}
catch
{
throw;
}
}
I hope it will help you.