|
-
January 7th, 2008, 12:59 AM
#1
How to get text selected row of grid view
how to get the text of a particular cell of selected row in grid view.
-
January 7th, 2008, 01:19 AM
#2
Re: How to get text selected row of grid view
Code:
Dim str As String = myGridView.SelectedRow.Cells(index).Text
-
January 7th, 2008, 01:31 AM
#3
Re: How to get text selected row of grid view
Thank u for your reply
same thing i have tried.like........
protected void gv1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
string strText = gv1.SelectedRow.Cells[0].Text.ToString();
}
but it is giving error like "object reference not set to an instance of object".
in which event i should write this code.............
-
January 7th, 2008, 02:26 AM
#4
how to get text of a particular cell of selected row in grid view
here is my code........
protected void myGridview_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
string strText = myGridview.SelectedRow.Cells[0].Text.ToString();
}
it is giving error like "object reference not set to an instance of object".
in which event i should write this code.............
-
January 7th, 2008, 03:15 AM
#5
Re: how to get text of a particular cell of selected row in grid view
You should first check if the selected row is a valid object.
Code:
// Get the row
Row selectedRow = myGridView.SelectedRow;
// Check if we have a valid row
if (selectedRow != null)
{
// Get the first column (only directly call to a column index if you are SURE it exists)
string text = selectedRow.Cells[0].Text;
}
Disclaimer:
I wrote this out of my head, so it's possible it contains some typos.
-
January 7th, 2008, 06:47 AM
#6
Re: How to get text selected row of grid view
Which reference is null? gv1? gv1.SelectedRow? gv1.SelectedRow.Cells? gv1.SelectedRow.Cells[0]?
Also, why are you calling the ToString method of a String?
-
January 7th, 2008, 01:34 PM
#7
Re: How to get text selected row of grid view
Code:
.... gv1.SelectedRow.Cells[0]?
Why are you using zero instead of the index of the column you need to get ? or do you want to get index zero ??
The other point is: Using this web control the event SelectedIndexChanging you are using is called before the change occurs. So in the first occurance of it this event will not have a selected row so it is null and you will have an Exception thrown. On the other side,you cannot use SelectedRow.Cells as you will get no or a former selection which is of no use. Using this event you need to do
Code:
gv1.Rows[e.NewSelectedIndex].Cells[clumnIndex].Text
otherwise it wouldn't work
This event is used before changing the selection !! So normally you use it for checking and eventually cancelling the selections change. If you want to use selectedRow you need to use the SelectedIndexChanged event
Hope this ends your troubles
Last edited by JonnyPoet; January 7th, 2008 at 02:02 PM.
 Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
-
January 7th, 2008, 02:05 PM
#8
Re: how to get text of a particular cell of selected row in grid view
Please dont double Post. the solution I have done in your other post. You are using the wrong event ! See your other post for why and how to handle that.
 Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|