Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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 Search this Thread Display Modes
  #1 (permalink)  
Old March 24th, 2006, 01:22 AM
Authorized User
 
Join Date: Mar 2006
Location: pune, Maharashtra, India.
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem in deleting the row from datagrid

Hi,
I want to use template column to delete a row from datagrid. I want to use sqlcommand object to directly give delete command based on the primary key. I have taken template column with image button. I have also supplied the commandname property to template column. now i want get the primary key of table inside delete event of grid.This is the value of the first column in grid. I have coded everything but i am getting the value as "".

Please help me. thank you.

  #2 (permalink)  
Old March 24th, 2006, 01:40 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

Is the key value you want to get inside of a template column?

Jim

  #3 (permalink)  
Old March 24th, 2006, 02:01 AM
Authorized User
 
Join Date: Mar 2006
Location: pune, Maharashtra, India.
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is the code for template column

<asp:TemplateColumn>
<HeaderStyle Width="20%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate><asp:ImageButton id=imbtdelete runat="server" CommandName="delete" CommandArgument='<% # DataBinder.Eval(Container,"DataItem.dev_code") %>' AlternateText="Delete" ImageUrl="images\delete.gif">
</asp:ImageButton>
</ItemTemplate>
</asp:TemplateColumn>

dev_code is the primary key that i want to access in delete event of the grid. dev_code is the first column of the grid. how to the this value?



  #4 (permalink)  
Old March 24th, 2006, 02:04 AM
Authorized User
 
Join Date: Mar 2006
Location: pune, Maharashtra, India.
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

also please explain me what object e returns. i know ASP very well but i am new to asp.net. so i have lot of queries. Please help me out.

  #5 (permalink)  
Old March 24th, 2006, 02: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

e is an object that represents command arguments for the event. You can get more info in vs help.

You cannot use the standard events of the datagrid since you are using an image button. What you need to do is:
1. Appned this to the HTML of your image button:
     OnCommand="DataGrid1_DeleteCommand
2. Add your event to the codebehind:
    Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As CommandEventArgs)
        Response.Write(e.CommandArgument)
    End Sub

When you click the image button that event will be fired. You can name it whatever you want.

Jim
  #6 (permalink)  
Old March 24th, 2006, 03:18 AM
Authorized User
 
Join Date: Mar 2006
Location: pune, Maharashtra, India.
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It worked. Thank you very much. one more question. I am using datasets to store the table. One one form I have filled the dataset. I am storing it in session variable and accessing it in another forms using Ctype. Is there any other way better that this to access dataset globally in whole application?

  #7 (permalink)  
Old March 24th, 2006, 03:22 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

Nope that's the way you have to do it, and using CType is the key. You could store in an application var or cache the ds but that is only good if you are not chaning the data.

Glad it worked

  #8 (permalink)  
Old March 24th, 2006, 03:32 AM
Authorized User
 
Join Date: Mar 2006
Location: pune, Maharashtra, India.
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

but if I access the dataset using ctype and now i want to add the records or update the records. the i need a new instance of data adapter. how should i go about doing this?

  #9 (permalink)  
Old March 24th, 2006, 03:37 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

YOu can update the dataset directly or just create an instance of a sqldataadapter.

  #10 (permalink)  
Old March 24th, 2006, 03:50 AM
Authorized User
 
Join Date: Mar 2006
Location: pune, Maharashtra, India.
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am confused. In one form I have declare a dataset(ds) and filled it with three tables. I have stored it in session variable(ds). then in another form I wanted to access one of the three tables. then i created new instance of dataset(ds1) and used following statement to get data
ds1 = CType(Session("ds"), DataSet)

now if i update the dataset ds1. how the changes will be reflected to all the forms? and if add new table into the database in another form. I want all the changes to be reflected to whole application. how can i acheive this?

I think i should again assign the ds1 to session variable. but when (in which event should i assign ds1 to the session variable again)

also in the first form where i am creating original dataset and assiging it to session. how can i get the new changes in the database?


 


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
Deleting a row of an array Singh591 VB.NET 2002/2003 Basics 1 July 23rd, 2007 04:51 PM
deleting row in a datagrid * nightmare :-( chrismogz ADO.NET 4 October 30th, 2006 05:47 PM
Deleting a row in excel sheet using c# livehed General .NET 1 May 17th, 2006 03:02 PM
Deleting every other row Russ Thompson Beginning VB 6 1 December 15th, 2004 05:20 AM



All times are GMT -4. The time now is 03:23 PM.


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