473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Datagrid: get value from the row selected by user

What I want to do is to retrive the value from the row
that was selected by uesr. I added the "Select" command
column and linked the select event to one of my method by
setting my DataGrid's attribute:
OnSelectedIndexChanged="OnSelectRow"

Now comes the problem. Even though I can invoke this
OnSelectRow method, I can only do so when I have the
following signiture:
Protected Sub OnSelectRow(ByVal sender As Object, _
ByVal e As System.EventArgs)

This doesn't help me because System.EventArgs doesn't give
me what I need.

Can somebody help me on how to do this? What signiture
should I use in this case?

Thanks
Nov 17 '05 #1
1 14139
I think you want to use grid.SelectedIndex or grid.SelectedItem in this
event instead of the generic EventArgs.

If you defined a DataKeyField attribute on your grid you can do something
like so instead the event:

Dim KeyID = Ctype(grid.DataKeys(grid.SelectedIndex), integer)
Another approach is to use the ItemCommand event instead (which gets fired
prior to the more specific SelectedIndexChanged). Note: in the ItemCommand
event your grid.SeletecIndex is the previously selected row, not the current
one (it doesn't change until SelectedIndexChanged fires).

Protected Sub HandleCommand(ByVal s As Object, ByVal e As
DataGridCommandEventArgs) Handles grid.ItemCommand

If e.CommandName = "Select" Then
Dim KeyID As Integer = CType(grid.DataKeys(e.Item.ItemIndex),
Integer)
End If

End Sub

HTH,
Greg
"Northern" <li******@msn.com> wrote in message
news:02****************************@phx.gbl...
What I want to do is to retrive the value from the row
that was selected by uesr. I added the "Select" command
column and linked the select event to one of my method by
setting my DataGrid's attribute:
OnSelectedIndexChanged="OnSelectRow"

Now comes the problem. Even though I can invoke this
OnSelectRow method, I can only do so when I have the
following signiture:
Protected Sub OnSelectRow(ByVal sender As Object, _
ByVal e As System.EventArgs)

This doesn't help me because System.EventArgs doesn't give
me what I need.

Can somebody help me on how to do this? What signiture
should I use in this case?

Thanks

Nov 17 '05 #2

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

Similar topics

4
by: Steve | last post by:
Visual Studio 2003 .Net / C# I have a datagrid, which is bound to a dataset at runtime when my page loads. When the user double clicks a row, I need to find out which row they have selected so...
1
by: Soul | last post by:
*** I am not sure this question belong to *.languages.csharp or *.framework.windowsdorms.databinding, so I post to both *** Hi, Currently I have a DataGrid which bind to a DataSet. One of...
2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
7
by: DJ Dev | last post by:
Hi All, I have a complex problem. I have dropdownlists (usually 3-5) and the user selects some value from these and for each value selected, datagrids are shown to the user. I am creating the...
4
by: Pacific Design Studios | last post by:
I have a DataGrid on Form1 that displays a small amount of information about employees. On Form2 I want to have all the data displaying in text boxes about the employee selected in the datagrid on...
2
by: zambizzi | last post by:
....I can't seem to get my hands on a control I'm loading in an editable datagrid. Here's my datagrid control: <asp:datagrid id="GLRulesGrid" runat="server" autogeneratecolumns="False"...
4
by: Mark Waser | last post by:
I've discovered a very odd bug when attempting to put a dropdown list in a datagrid. In the page PreRender step, the selected index of the datagrid is successfully set during databinding. Yet,...
4
by: Anthony | last post by:
Hi Folks, I'm adding some columns to my datagrid which are of Combo Box type. I'm inheriting DataGridTextBoxColumn and doing all the usual stuff to get them populated. This is working fine. I...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.