Click here to Skip to main content
Click here to Skip to main content

how can we change the value of one column on change of other column in gridview.

By , 12 Jun 2012
 

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

coolnavjot31
Software Developer
India India
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberPrasad_Kulkarni13 Jun '12 - 2:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 12 Jun 2012
Article Copyright 2012 by coolnavjot31
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid