0

enter image description here

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.

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;
    }

P.S.: I have not done this programmatically. The only code I've wrote on .aspx.cs file is the code above.

aldoblack
  • 175
  • 3
  • 20
  • what type of `GridView1.Rows[e.NewSelectedIndex].Cells[1].Value` do you get? – Andrew Apr 19 '14 at 14:14
  • @Andrew, NULL as you see it is (NULL) 2 4 I have Selected the second Row. – aldoblack Apr 19 '14 at 14:15
  • how do you create your control? http://stackoverflow.com/questions/7305905/dropdownlist-in-gridview-asp-net – Andrew Apr 19 '14 at 14:31
  • No, it doesn't work. Any other idea? :/ – aldoblack Apr 19 '14 at 14:42
  • how do you create your grid and how do you add dropdown to it? – Andrew Apr 19 '14 at 14:51
  • Nor programmatically. I dragged a GridView from ToolBox, Chose Data Source and binded it with datasource. I edited template, convertet a column into a TemplateField and then added the DropDownliast. This is the code http://pastebin.com/tEu3HicJ – aldoblack Apr 19 '14 at 15:09

1 Answers1

2

Use this to find the value. its not showing the value because of template field control. I have used the gridview control that you pasted in pastebin.

protected void GridView_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) {

      Label drpValue =
      (Label)this.GridView1.Rows[e.NewSelectedIndex].Cells[1].FindControl("Label1");
      Lbl1.Text = drpValue.Text; 
      Lbl2.Text = GridView1.Rows[e.NewSelectedIndex].Cells[2].Text;
      Lbl3.Text = GridView1.Rows[e.NewSelectedIndex].Cells[3].Text;

}
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Deepak Tiwary
  • 120
  • 2
  • 12