Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

http://i.stack.imgur.com/fNHoc.png


So, when I click Select I want to show in a Label all datas that contain one row. I have managed to make this, except DropdownList. When I click "Select" it's just empty. Like in the picture above.
P.S.: I have not done this programmatically. The only code I've wrote on .aspx.cs file.

C#
protected void GridView_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        Label1.Text = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text;
        Label2.Text = GridView1.Rows[e.NewSelectedIndex].Cells[2].Text;
        Label3.Text = GridView1.Rows[e.NewSelectedIndex].Cells[3].Text;
    }
Posted

Try below code inside the SelectedIndexChanging Event.
C#
GridViewRow row = GridView1.Rows[e.NewSelectedIndex];
DropDownList ddl = row.FindControl("ddlDropDownList") as DropDownList;
someLabel.Text = ddl.SelectedValue.ToString();


OP 's reply

Nope. It doesn't work, but I figured out the solution. It is:
C#
Label drpValue = (Label)this.GridView1.Rows[e.NewSelectedIndex].Cells[1].FindControl("Label1");
Lbl1.Text = drpValue.Text;
 
Share this answer
 
v3
Comments
AldoBlack 20-Apr-14 10:23am    
Nope. It doesn't work, but I figured out the solution. It is:
Label drpValue = (Label)this.GridView1.Rows[e.NewSelectedIndex].Cells[1].FindControl("Label1");
Lbl1.Text = drpValue.Text;
Okay. I thought it was a DropDownList, so I suggested that code. But according to your code, it seems like a Label. I updated the answer. Please accept that.
AldoBlack 21-Apr-14 8:30am    
Of course it is a dropdownlist. I have posted a screenshot of my gridview. Take a look. :)
But the way you are trying to get it, it seems like a Label.

Label drpValue = (Label)this.GridView1.Rows[e.NewSelectedIndex].Cells[1].FindControl("Label1");

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