Click here to Skip to main content
15,891,657 members
Articles / Web Development / ASP.NET
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
12 Jun 2012CPOL 16.6K   1
In this Artcile i will show you how can we change the value of one column on change of other column in gridview.

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. 

C++
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)


Written By
Software Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Prasad_Kulkarni13-Jun-12 2:19
Prasad_Kulkarni13-Jun-12 2:19 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.