473,320 Members | 1,868 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,320 software developers and data experts.

datagrid in a asp.net page

JD
Hello Everyone,

I am writing a asp.net page using vb.net with a datagrid control. I am
trying to detect when a row is clicked on in the grid. And I am not sure how
to do this, if anyone has any ideas on this I would really appreciate your
help. Thanks.

--
J. D
Nov 19 '05 #1
4 1292
Add a button in your DataGrid, give it a CommandName="Click", then handle
the DataGrid's ItemCOmmand event. If the ItemCommandEventArgs.CommandName
matches your Button's COmmandName ("Click" in this case), then the ItemCommandEventArgs.Item
is the row that was clicked and its index in the DataGrid is ItemCommandEventArgs.Item.ItemIndex.
-Brock
DevelopMentor
http://staff.develop.com/ballen
Hello Everyone,

I am writing a asp.net page using vb.net with a datagrid control. I am
trying to detect when a row is clicked on in the grid. And I am not
sure how to do this, if anyone has any ideas on this I would really
appreciate your help. Thanks.


Nov 19 '05 #2
JD
I originally did that but the client didn't like the idea of the button on
the screen, they felt it was somewhat confusing to click on a button to
select a record and then click on another button to save the change.

Is it possible to make the datagrid work like a spreadsheet where you select
a row and highlight the selected row and then handle it appropiately.
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:34**********************@msnews.microsoft.com ...
Add a button in your DataGrid, give it a CommandName="Click", then handle
the DataGrid's ItemCOmmand event. If the ItemCommandEventArgs.CommandName
matches your Button's COmmandName ("Click" in this case), then the
ItemCommandEventArgs.Item is the row that was clicked and its index in the
DataGrid is ItemCommandEventArgs.Item.ItemIndex.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hello Everyone,

I am writing a asp.net page using vb.net with a datagrid control. I am
trying to detect when a row is clicked on in the grid. And I am not
sure how to do this, if anyone has any ideas on this I would really
appreciate your help. Thanks.


Nov 19 '05 #3
JD try stepping through this Article at:-
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx
Hope it helps!
Patrick


*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #4
If you want server-side onclick event processing add a hidden column like
this:

<asp:ButtonColumn ButtonType="LinkButton" CommandName="Select"
Visible="False"></asp:ButtonColumn>

and handle ItemDataBound event like this:

protected void myGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if ((itemType == ListItemType.Pager) ||
(itemType == ListItemType.Header) ||
(itemType == ListItemType.Footer))
{
return;
}
LinkButton button = (LinkButton) e.Item.Cells[0].Controls[0];
e.Item.Attributes["onclick"] = this.GetPostBackClientHyperlink
(button, "");
}

The example presumes the the column is the very first one in the grid.
Eliyahu

"JD" <jd****@dalys.us> wrote in message
news:u7****************@TK2MSFTNGP10.phx.gbl...
I originally did that but the client didn't like the idea of the button on
the screen, they felt it was somewhat confusing to click on a button to
select a record and then click on another button to save the change.

Is it possible to make the datagrid work like a spreadsheet where you select a row and highlight the selected row and then handle it appropiately.
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:34**********************@msnews.microsoft.com ...
Add a button in your DataGrid, give it a CommandName="Click", then handle the DataGrid's ItemCOmmand event. If the ItemCommandEventArgs.CommandName matches your Button's COmmandName ("Click" in this case), then the
ItemCommandEventArgs.Item is the row that was clicked and its index in the DataGrid is ItemCommandEventArgs.Item.ItemIndex.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hello Everyone,

I am writing a asp.net page using vb.net with a datagrid control. I am
trying to detect when a row is clicked on in the grid. And I am not
sure how to do this, if anyone has any ideas on this I would really
appreciate your help. Thanks.



Nov 19 '05 #5

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

Similar topics

3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
8
by: Sue | last post by:
I have a datagrid populated with 6 visible read-only labels and several hidden fields. Below the datagrid, I have a table with various textboxes, dropdowns, etc. I've managed to decypher the...
2
by: enak | last post by:
I can not get my datagrid to page. I have a datagrid that I can sort 2 of the columns. This works great. I added paging and when I display the dg it shows 5 pages. (I am showing page numbers at...
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...
3
by: CVerma | last post by:
Hi, I have an embedded datagrid within a datalist. I am not able to perfrom paging in the datagrid. Any ideas? Here is my code: Here is my Simplegrid.cs file: using System; using...
4
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a...
6
by: Shawn | last post by:
Hi. I already have a datagrid where I'm using paging. I have a stored procedure that fills a temp table with 200-500 rows and then sends back 10 records at the time. When I go to page 2 the SP...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
8
by: Brock | last post by:
I am trying to populate a Crystal Report from data in my DataGrid. The reason for this is that I want the user to be able to change values without updating the database, but still have their report...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.