Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir,

i have a grid view in which one column consist of itemtemplate with Dropdown

i binded first dropdown in a column
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
       {

           if (e.Row.RowType == DataControlRowType.DataRow)
           {
               if (e.Row.RowIndex == 0)
               {
                   DataTable dt = new DataTable();
                   string str1 = e.Row.Cells[4].Text.ToString();
                   string str2 = "0";
                   dt = BLAutoComplete.GetFirstDdl(str1, str2);
                   DropDownList DDL = (DropDownList)e.Row.FindControl("ddl1");
                   DDL.DataSource = dt;
                   DDL.DataTextField = "CURRENT_NAME";
                   DDL.DataValueField = "CURRENT_ID";
                   DDL.DataBind();
                   DDL.Items.Insert(0, "--Select--");

               }
           }
       }

i need first row dropdown selectedindex change i need to bind same column second row dropdown
Posted
Updated 13-Dec-10 20:11pm
v2

What if you remove the following condition?
if (e.Row.RowIndex == 0)
 
Share this answer
 
v2
Comments
Toniyo Jackson 14-Dec-10 6:03am    
Always put your code inside code block.
saini arun 14-Dec-10 6:09am    
Thanks for the correction.

Don't think it is necessary for a single line of code containing hardly 4 or 5 words.
test-09 14-Dec-10 6:25am    
The dropdownlist in each row is bounded but I think the op wants when a list item is selected in first row then the dropdownlist in second should be bind.
saini arun 14-Dec-10 6:31am    
Ah! yes you are right. My bad.
Create an even handler for dropdown selection changed in row databound event and in dropdownselectionchanged event
foreach (GridViewRow gr in GridView1.Rows)
        {
            DropDownList DDL = (DropDownList)gr.FindControl("DropDownList2");
            if (gr.RowIndex == 1)
            {
            // code to populate dropdownlist    
            }
        }
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900