GridView1_SelectedIndexChanged

how assign the selected index in the label control

Page 1 of 1

3 Replies - 28502 Views - Last Post: 05 February 2011 - 12:25 PM Rate Topic: -----

#1 newProgram  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 160
  • Joined: 28-October 08

GridView1_SelectedIndexChanged

Post icon  Posted 07 December 2008 - 10:49 PM

hi to all,

asking for help how do I assign the values I've selected in the gridview to the label control. I try using the different tutorials in the internet but nothing happens.

here's my code:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
	{
		GridViewRow row = GridView1.SelectedRow;

		lblClinicName.Text = Convert.ToString(row.Cells[1].Text);
		lblStreet.Text = row.Cells[2].Text;
		lblCity.Text = row.Cells[2].Text;
		lblTelNo.Text = row.Cells[2].Text;
		lblClinicSched.Text = row.Cells[2].Text;
	}


thanks to all.

Is This A Good Question/Topic? 1

Replies To: GridView1_SelectedIndexChanged

#2 webwired  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 33
  • View blog
  • Posts: 339
  • Joined: 26-August 07

Re: GridView1_SelectedIndexChanged

Posted 08 December 2008 - 03:16 PM

You can do this if you have a GridView and a DetailsView... It's called Master/Detail, you can find a great tutorial video here... http://www.asp.net/l...s/video-07.aspx
DetailsView1.PageIndex = GridView1.SelectedIndex;


Was This Post Helpful? 0
  • +
  • -

#3 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: GridView1_SelectedIndexChanged

Posted 08 December 2008 - 06:34 PM

Are you using the Select button of the GridView to select a row?

If so, then you are on the right track. However, you should have a different index number for each Cell that you are getting information from in the GridViewRow. The index starts at 0 for the Cells.

I made a guess as to what the index numbers of each Cell should be, but you might need to modify them to make it work with the correct column in the GridView.
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
	{
		GridViewRow row = GridView1.SelectedRow;

		lblClinicName.Text = row.Cells[0].Text;
		lblStreet.Text = row.Cells[1].Text;
		lblCity.Text = row.Cells[2].Text;
		lblTelNo.Text = row.Cells[3].Text;
		lblClinicSched.Text = row.Cells[4].Text;
	}

Was This Post Helpful? 1

#4 Guest_Tushar Fulmali*


Reputation:

Re: GridView1_SelectedIndexChanged

Posted 05 February 2011 - 12:25 PM

Thank You Very Much
Was This Post Helpful? 0

Page 1 of 1