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.

, 12 Jun 2012
Rate this:
Please Sign up or sign in to vote.
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. 

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)

Share

About the Author

coolnavjot31
Software Developer
India India
No Biography provided

Comments and Discussions

 
GeneralMy vote of 5 PinmemberPrasad_Kulkarni13-Jun-12 2:19 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 12 Jun 2012
Article Copyright 2012 by coolnavjot31
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid