 |
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 24th, 2006, 01:22 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

March 24th, 2006, 01:40 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Is the key value you want to get inside of a template column?
Jim
|
|

March 24th, 2006, 02:01 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

March 24th, 2006, 02:04 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

March 24th, 2006, 02:38 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
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
|
|

March 24th, 2006, 03:18 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

March 24th, 2006, 03:22 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
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
|
|

March 24th, 2006, 03:32 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

March 24th, 2006, 03:37 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
YOu can update the dataset directly or just create an instance of a sqldataadapter.
|
|

March 24th, 2006, 03:50 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|
 |