Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 26th, 2005, 10:35 AM
Registered User
 
Join Date: Dec 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataGrid onclick event?


I'm new her and I hope to find someone who can help me in my problem.
My problem is:
I need to get the key value from the selected row in datagrid so I can bind another datagrid from this value.
And I must use onclick event to do this.
Any ideas I'll very thankfull.

Regards
  #2 (permalink)  
Old December 28th, 2005, 02:48 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Can I ask, why must you use onclick?

Jim
  #3 (permalink)  
Old December 28th, 2005, 04:01 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

When you bind a datagrid, usually you would set the DataKeyField to the database field containing your primary key. When you select a row, you can get at the rows key value via the DataKeys property.

   grid.DataKeys[grid.SelectedIndex]

On what do you wish to click to select the row?

-Peter
  #4 (permalink)  
Old December 29th, 2005, 03:50 AM
Registered User
 
Join Date: Dec 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your responces.
Jim: I need to use onclick because the customer wanted to be like that and they refuse to put any buttons in the grid.

Peter: Your code is ok with buttons but her i'm not using any buttons. I wante to click any where in the row to be selected, also the project leader wanted to be OnDoubleClick event :(

Regards

Hani
  #5 (permalink)  
Old December 29th, 2005, 11:38 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

First I would ask the customer why they want no buttons. This seems very stupid to me. It would not be intuative for the user to click or double click a row to do something. Have a button or hyperlink is makes much more sense, and will be more user friendly. Talk to them about it.


Here is a quick example, assuming your ID column is in the first column, calls a function called test() The test function just does a simple alert, but once you have the value you can do whatever with it:
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then

   e.Item.Attributes.Add("onDblClick", "test(" + e.Item.Cells(0).Text + ")")

End If
  #6 (permalink)  
Old December 29th, 2005, 05:16 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

One trick I have used is this:

Add a non-visible select column to your grid:

    <asp:buttoncolumn text="Select" commandname="Select" visible="False" />

Then in the codebehind, you can get at the select button in the appropriate cell and assign its client-side event handler code to the row's double click event. You'll have to do that in the page's pre-render event handler because of the way the datagrid control structure is built.

    Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
        For Each objItem As DataGridItem In DataGrid1.Items
            Select Case objItem.ItemType
                Case ListItemType.AlternatingItem, ListItemType.Item
                    objItem.Attributes("ondblclick") = GetPostBackClientEvent(objItem.Cells(0).Controls(0 ), String.Empty)
            End Select
        Next
    End Sub


-Peter
  #7 (permalink)  
Old December 30th, 2005, 12:19 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Cool trick Peter!

  #8 (permalink)  
Old January 1st, 2006, 05:21 AM
Registered User
 
Join Date: Dec 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much.

Happy New Year :)

Hani
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
onclick event bjackman Access 6 July 15th, 2004 06:54 AM
onclick event pigtail Javascript 1 April 11th, 2004 03:10 PM
onClick Event mateenmohd Javascript 4 December 16th, 2003 01:08 AM
onClick event problem mateenmohd Javascript 8 August 2nd, 2003 05:16 AM



All times are GMT -4. The time now is 02:20 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.