Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics 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 Display Modes
  #1 (permalink)  
Old November 16th, 2008, 01:50 PM
Authorized User
 
Join Date: Nov 2008
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default datagrid command buttons

Hello,
I have a datagrid that is connected to ms-access DB.
I would like to make a delete link for each row, that clicking on that link will delete its value from the DB

I tried to add "ondelete" command,
and add a linkbutton to the templatecoulm, but that script is never executed when i click!

How can i call a sub when i click on a button in the templatecoulm?


thsnk you !

  #2 (permalink)  
Old November 18th, 2008, 05:54 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Just curious -- why are you using a DataGrid instead of a GridView?

_________________________________

Visit my blog at http://leedumond.com
  #3 (permalink)  
Old November 19th, 2008, 03:29 AM
Authorized User
 
Join Date: Nov 2008
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

what is greedview?

  #4 (permalink)  
Old November 19th, 2008, 03:58 AM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

The GridView is the thing that has replaced the DataGrid since ASP.NET 2.0.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview(VS.80).aspx

You should not be using the DataGrid any more, unless you're still on 1.0. Use a GridView (or possibly a ListView, if you're working in 3.5).

_________________________________

Visit my blog at http://leedumond.com
  #5 (permalink)  
Old November 22nd, 2008, 12:19 PM
Authorized User
 
Join Date: Nov 2008
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi there,
I switched to GridView.

Can you explain me please how do i get the value of a specific field in the row that i select\button click on it?

thank you
  #6 (permalink)  
Old November 22nd, 2008, 01:28 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

You would handle the SelectedIndexChanged event of the GridView.

You wanted to know how to get the value of a specific field in a selected row, right?

Okay, let's say you want the value of something in the third column. That would be index #2 in the cells collection of that row (remember, the index starts at 0).

So, you'd go like this:

Code:
    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
     Handles GridView1.SelectedIndexChanged
        Dim row As GridViewRow = GridView1.SelectedRow
        Label1.Text = "You selected " & row.Cells(2).Text & "!"
    End Sub
The above code would take whatever is displayed in the third column of the selected row, and display it in a label. Of course, you could do whatever you need to with that value.

_________________________________

Visit my blog at http://leedumond.com
  #7 (permalink)  
Old November 22nd, 2008, 02:50 PM
Authorized User
 
Join Date: Nov 2008
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yjank you,

Does it work with the rowdeleting event?

But counting the cells sounds premitive.

|Imagine you have a table with 100 fields..
You need to count each cell till you get the one you want?
  #8 (permalink)  
Old November 22nd, 2008, 10:18 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

I'm not sure what you're asking.

You can easily create a CommandField with a Delete button in it. But are you asking if it's possible to get the value of a field in a row you are deleting?



_________________________________

Visit my blog at http://leedumond.com
  #9 (permalink)  
Old November 23rd, 2008, 06:34 AM
Authorized User
 
Join Date: Nov 2008
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi there.

I need to create a rowdeleting event,
in that event i have to create a sql statment that deleted the record from the db.

I have an invisible field with the rowID of every row displayed.

I need to get that ID when i click on the delete button...



  #10 (permalink)  
Old November 23rd, 2008, 11:38 AM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

You don't have to do any of that when deleting records, as the Gridview supports deleting records directly through the datasource to which it is bound.

Let's say you had a list of products, and the primary key is called ProductID. By specifying the DataKeyNames="ProductID" in the Gridview, you can configure it to automatically call the Delete method of the datasource, passing the primary key as the parameter.

So, your GridView may look something like this:
Code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true" 
   DataKeyNames="ProductID" DataSourceID="SqlDataSource1" AutoGenerateDeleteButton="True">
</asp:GridView>
and your datasource would look like this:
Code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
   ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" 
   SelectCommand="SELECT [ProductName], [QuantityPerUnit], [ProductID], [UnitPrice] FROM [Products]" 
   DeleteCommand="DELETE FROM [Products] WHERE [ProductID] = @ProductID"           
      <DeleteParameters>
         <asp:Parameter Name="ProductID" Type="Int32" />
      </DeleteParameters>          
</asp:SqlDataSource>
This will automatically create the deletebutton, which will automatically call the delete method in the datasource when clicked.

_________________________________

Visit my blog at http://leedumond.com
 


Thread Tools
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
Using command buttons in Access kelljw Access VBA 10 July 5th, 2006 01:42 PM
Using command buttons in Access kelljw BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 July 4th, 2006 08:21 AM
Labels as command buttons RichMW Access VBA 0 February 18th, 2005 09:10 AM
Graphics For Command Buttons Teqlump Access 1 November 24th, 2004 11:02 AM
Datagrid command buttons badgolfer ASP.NET 1.0 and 1.1 Basics 22 July 27th, 2004 03:42 AM



All times are GMT -4. The time now is 10:52 AM.


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