473,763 Members | 9,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get data from selected record in gridview

Hi all, this is a second post, so apologies, but I never had an answer to my
first post (several weeks ago) and I really need some help.

I'm using a .Net 2.0 Gridview which is populated using an ObjectDataSourc e
which calls on a method in a class. This all works fine.

The Gridview has a select button automatically generated. When the user
presses this I want to be able to take the data from the selected record and
use it. However whatever I try, I can't seem to be able to get hold of the
data.

Can anyone help me? How do you read the data in the selected record of a
Gridview?

Thanks in advance.
Julia

Oct 21 '08 #1
7 11060
Hallo Julia,

i did this for a customer a long time ago.
One way is to implement the Gridviews rowdataboundeve nt, take the row from
the passed in event argument, check if it's rowtype is
DataControlRowS tate.Selected
and save the values you need in the viewstate.
Another way would be to enrich the attributes collection of the button
during databinding with the needed values.
The usual way is to use the grids SelectedDataKey property and supply a key
in the definition from the grid.

Regards

Winfried Wille

"Julia B" <Ju****@discuss ions.microsoft. comwrote in message
news:3B******** *************** ***********@mic rosoft.com...
Hi all, this is a second post, so apologies, but I never had an answer to
my
first post (several weeks ago) and I really need some help.

I'm using a .Net 2.0 Gridview which is populated using an ObjectDataSourc e
which calls on a method in a class. This all works fine.

The Gridview has a select button automatically generated. When the user
presses this I want to be able to take the data from the selected record
and
use it. However whatever I try, I can't seem to be able to get hold of the
data.

Can anyone help me? How do you read the data in the selected record of a
Gridview?

Thanks in advance.
Julia
Oct 21 '08 #2
Hi and thanks for the response.

I'm new to .Net 2.0 and am struggling to understand how Gridviews work as
opposed to 1.0 Datagrids.

I'm not sure I understand how to implement the selecteddatakey solution. I
have found several "samples" but none of them seem to work. Do you know of
any examples that I can look at?

Thanks
"Winfried Wille" wrote:
Hallo Julia,

i did this for a customer a long time ago.
One way is to implement the Gridviews rowdataboundeve nt, take the row from
the passed in event argument, check if it's rowtype is
DataControlRowS tate.Selected
and save the values you need in the viewstate.
Another way would be to enrich the attributes collection of the button
during databinding with the needed values.
The usual way is to use the grids SelectedDataKey property and supply a key
in the definition from the grid.

Regards

Winfried Wille

"Julia B" <Ju****@discuss ions.microsoft. comwrote in message
news:3B******** *************** ***********@mic rosoft.com...
Hi all, this is a second post, so apologies, but I never had an answer to
my
first post (several weeks ago) and I really need some help.

I'm using a .Net 2.0 Gridview which is populated using an ObjectDataSourc e
which calls on a method in a class. This all works fine.

The Gridview has a select button automatically generated. When the user
presses this I want to be able to take the data from the selected record
and
use it. However whatever I try, I can't seem to be able to get hold of the
data.

Can anyone help me? How do you read the data in the selected record of a
Gridview?

Thanks in advance.
Julia
Oct 21 '08 #3
Thanks for your help, found this:

http://msdn.microsoft.com/en-us/libr...lectedrow.aspx

"Winfried Wille" wrote:
Hallo Julia,

i did this for a customer a long time ago.
One way is to implement the Gridviews rowdataboundeve nt, take the row from
the passed in event argument, check if it's rowtype is
DataControlRowS tate.Selected
and save the values you need in the viewstate.
Another way would be to enrich the attributes collection of the button
during databinding with the needed values.
The usual way is to use the grids SelectedDataKey property and supply a key
in the definition from the grid.

Regards

Winfried Wille

"Julia B" <Ju****@discuss ions.microsoft. comwrote in message
news:3B******** *************** ***********@mic rosoft.com...
Hi all, this is a second post, so apologies, but I never had an answer to
my
first post (several weeks ago) and I really need some help.

I'm using a .Net 2.0 Gridview which is populated using an ObjectDataSourc e
which calls on a method in a class. This all works fine.

The Gridview has a select button automatically generated. When the user
presses this I want to be able to take the data from the selected record
and
use it. However whatever I try, I can't seem to be able to get hold of the
data.

Can anyone help me? How do you read the data in the selected record of a
Gridview?

Thanks in advance.
Julia
Oct 21 '08 #4
Hallo Julia,

fine you found a solution. Selectedrow is another working way, but as you
have seen in the sample, you have to dig into the cell contents, to get your
value .
If you have further problems, i would have looked for some sample code
lines/sample.

Good Luck
Winfried Wille

"Julia B" <Ju****@discuss ions.microsoft. comwrote in message
news:DA******** *************** ***********@mic rosoft.com...
Thanks for your help, found this:

http://msdn.microsoft.com/en-us/libr...lectedrow.aspx
Oct 21 '08 #5
Thanks for your responses on this. I've got something working using
selectedrow as follows:

Dim row As GridViewRow = Me.dgAccounts.S electedRow
currentAcType.a ccountTypeOrigi nal = row.Cells(1).Te xt
Me.tbAcc.Text = row.Cells(1).Te xt
If row.Cells(4).Te xt <" " Then
Me.tbEmail.Text = row.Cells(4).Te xt
End If

This works fine, however I've got a problem with a couple of the cells which
are autogenerated checkboxes. Regardless of whether the display value is true
or false, the text value of the cell is always an empty string. Do you know
how I get the value of the checkbox?

Thanks
Julia

"Winfried Wille" wrote:
Hallo Julia,

fine you found a solution. Selectedrow is another working way, but as you
have seen in the sample, you have to dig into the cell contents, to get your
value .
If you have further problems, i would have looked for some sample code
lines/sample.

Good Luck
Winfried Wille

"Julia B" <Ju****@discuss ions.microsoft. comwrote in message
news:DA******** *************** ***********@mic rosoft.com...
Thanks for your help, found this:

http://msdn.microsoft.com/en-us/libr...lectedrow.aspx
Oct 22 '08 #6
Got it:

CType(row.Cells (9).Controls(0) , System.Web.UI.W ebControls.Chec kBox).Checked

"Julia B" wrote:
Thanks for your responses on this. I've got something working using
selectedrow as follows:

Dim row As GridViewRow = Me.dgAccounts.S electedRow
currentAcType.a ccountTypeOrigi nal = row.Cells(1).Te xt
Me.tbAcc.Text = row.Cells(1).Te xt
If row.Cells(4).Te xt <" " Then
Me.tbEmail.Text = row.Cells(4).Te xt
End If

This works fine, however I've got a problem with a couple of the cells which
are autogenerated checkboxes. Regardless of whether the display value is true
or false, the text value of the cell is always an empty string. Do you know
how I get the value of the checkbox?

Thanks
Julia

"Winfried Wille" wrote:
Hallo Julia,

fine you found a solution. Selectedrow is another working way, but as you
have seen in the sample, you have to dig into the cell contents, to get your
value .
If you have further problems, i would have looked for some sample code
lines/sample.

Good Luck
Winfried Wille

"Julia B" <Ju****@discuss ions.microsoft. comwrote in message
news:DA******** *************** ***********@mic rosoft.com...
Thanks for your help, found this:
>
http://msdn.microsoft.com/en-us/libr...lectedrow.aspx
>
Oct 22 '08 #7
Hallo Julia,

you can use something like this:
protected void GridView1_RowCo mmand(object sender,
GridViewCommand EventArgs e)
{
bool b = ((CheckBox)
(((GridView)sen der).SelectedRo w.Cells[2].Controls[0])).Checked;
}
Where 2 is used as the index for your autogenerated checkbox column.
You can download a sample here http://wtww2.de/downloads.gridview.zip.
Using this, you might have compatibilties problems in the future, because
you depend on the automatically generated html for the autogenerated
checkbox column, which is not obligatory specified.
I hope this helps you to progress on your project. If you go further into
asp.net programming, you should consider read a book and stay away from such
things as autogenerated columns.

Regards
Winfried Wille

"Julia B" <Ju****@discuss ions.microsoft. comwrote in message
news:B5******** *************** ***********@mic rosoft.com...
Thanks for your responses on this. I've got something working using
selectedrow as follows:

Dim row As GridViewRow = Me.dgAccounts.S electedRow
currentAcType.a ccountTypeOrigi nal = row.Cells(1).Te xt
Me.tbAcc.Text = row.Cells(1).Te xt
If row.Cells(4).Te xt <" " Then
Me.tbEmail.Text = row.Cells(4).Te xt
End If

This works fine, however I've got a problem with a couple of the cells
which
are autogenerated checkboxes. Regardless of whether the display value is
true
or false, the text value of the cell is always an empty string. Do you
know
how I get the value of the checkbox?
>"Julia B" <Ju****@discuss ions.microsoft. comwrote in message
news:DA******* *************** ************@mi crosoft.com...
Thanks for your help, found this:

http://msdn.microsoft.com/en-us/libr...lectedrow.aspx
Oct 22 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
14818
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1 but how is this done now in asp.net 2.0?
2
1752
by: dbuchanan | last post by:
Hello, I want to open a child form based on the record selected in a dataGridView of the parent form. I want the child form to open with a populated child table based on the selected parent record. How do I get the ID of the selected record in the parent form's dataGridView so I can use it in filling the child form's dataGridView?
1
1741
by: MikeB | last post by:
ooh boy, I hope I'm in the right place to ask this. I'm trying to do a class project that binds controls to data sources. I have a Drop-down List that I bound to the Author column of an SQL table Articles. I then have a GridView that is supposed to react to changes in the name selected in the DDL.
2
2858
by: Steve Kershaw | last post by:
Hi, I'm working on a project in which I have a Gridview that has data. That Gridview data must be then exported to an Excel spreadsheet. I have successfully displayed the Excel spreadsheet and fill it with data using the Range.InvokeMember(...) method: Range range2 = worksheet.get_Range("A1", "L1"); Object args2 = new Object;
7
2963
by: KiwiGenie | last post by:
I have a form which lists selected records, there could be anything from 1 record to all records selected. I want to output a report for each record as HTML. I want each file to take its name from a certain field (RecipeName), so can't simply put a page break in the report. Would it be possible to create a loop which opens the report hidden, then exports it to HTML, then closes the report, and does this for each selected record? Or would all...
1
2601
by: Bob | last post by:
Hello, Using VB 2005.net. I have a bound datagridview and a delete button control (or when the user pressed the 'Delete' key) I can successfully delete the selected record from the table and it is removed from the dgv. But then I want to select the previous row in the dgv and select it so on 'Select Index Changed' event I can populate text boxes referring to the selected row. The user may have selected the 5th row in the dgv then...
3
1657
by: btreddy | last post by:
Hiii experts , I've received one critical requirement from my customer this morning. I've a gridview,in one of my webpage, which displays all the prticipants who are participating in a perticular activity with an unique id.Now the requirment is i need to add one button/linkbutton up on ckicking tht i've to dispaly some of the coloums of the gridview in edit mode..in a seperate control.(like in another gridview) and update the...
2
2156
by: eneyardi | last post by:
How to filter selected record in a report? i have a form name Data Tracking Details where i can view my records one by one using record selector. Now, i want my current record in a form to be filtered in a report. i want to do this in a command button, when i press it, i can print the filtered record.
2
3273
by: David Patz | last post by:
Is it possible for a user to select a record from a datasheet in a subform, double click it, and write that specific record to another table? I have attempted to perform this task using DoCmd.DoMenuItem commands and RunCommand acCmds but with no luck? Im currently building this system in VBA with MS Access 2003. Thus far I have only been able to copy the selected record to a the windows clipboard to be used in other text-based platforms, but I...
0
9564
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.