473,695 Members | 2,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView and TemplateField Help

Greetings,

I have a GridView control. For a couple of reasons, I ended up with a
TemplateField to contain my Edit and Delete links, something like this:

<asp:TemplateFi eld ShowHeader="Fal se">
<EditItemTempla te>
<asp:LinkButt on ID="LinkButton1 " runat="server" CausesValidatio n="True"
CommandName="Up date" Text="Update"></asp:LinkButton>
&nbsp;<asp:Link Button ID="LinkButton2 " runat="server"
CausesValidatio n="False"
CommandName="Ca ncel" Text="Cancel"></asp:LinkButton>
</EditItemTemplat e>
<ItemTemplate >
<asp:LinkButt on ID="LinkButton1 " runat="server"
CausesValidatio n="False"
CommandName="Ed it" Text="Edit"></asp:LinkButton>
&nbsp;<asp:Link Button ID="lnkDelete" runat="server"
CausesValidatio n="false"
CommandName="De lete" Text="Delete"
OnClientClick=" return confirm('Are you sure you want to delete this
record?');" />
</ItemTemplate>

In addition, the GridView control is bound to an ObjectDataSourc e object
that contains the following:

<asp:ObjectData Source ID="ObjectDataS ource1" runat="server"
DeleteMethod="D eleteActivity" InsertMethod="I nsertActivity"
SelectMethod="G etActivities" TypeName="SoftC ircuits.MediCor p.Activities"
UpdateMethod="U pdateActivity">
<DeleteParamete rs>
<asp:Paramete r Name="activityI d" Type="Int32" />
</DeleteParameter s>
<UpdateParamete rs>
...
</UpdateParameter s>
<SelectParamete rs>
...
</SelectParameter s>
<InsertParamete rs>
...
</InsertParameter s>
</asp:ObjectDataS ource>

I'm trying to understand how some of this information hooks up. When I click
the delete link (and click OK in the confirmation), the DeleteActivity
method of SoftCircuits.Me diCorp.Activiti es does in fact get called. However,
the activityId argument is always 0.

Can anyone help me understand where the ObjectDataSourc e should be getting
this argument value from such that it would represent the id of the record
on the row for which the Delete link was clicked?

The activityId represents the primary key of the table being displayed.

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

Jun 27 '08 #1
4 1804
Set the GridView's DataKeyNames attribute value to activityId.

--
---------------------------------------------------
S.M. Altaf [MVP]
http://www.mendhak.com/
"Jonathan Wood" <jw***@softcirc uits.comwrote in message
news:Ow******** ******@TK2MSFTN GP06.phx.gbl...
Greetings,

I have a GridView control. For a couple of reasons, I ended up with a
TemplateField to contain my Edit and Delete links, something like this:

<asp:TemplateFi eld ShowHeader="Fal se">
<EditItemTempla te>
<asp:LinkButt on ID="LinkButton1 " runat="server"
CausesValidatio n="True"
CommandName="Up date" Text="Update"></asp:LinkButton>
&nbsp;<asp:Link Button ID="LinkButton2 " runat="server"
CausesValidatio n="False"
CommandName="Ca ncel" Text="Cancel"></asp:LinkButton>
</EditItemTemplat e>
<ItemTemplate >
<asp:LinkButt on ID="LinkButton1 " runat="server"
CausesValidatio n="False"
CommandName="Ed it" Text="Edit"></asp:LinkButton>
&nbsp;<asp:Link Button ID="lnkDelete" runat="server"
CausesValidatio n="false"
CommandName="De lete" Text="Delete"
OnClientClick=" return confirm('Are you sure you want to delete this
record?');" />
</ItemTemplate>

In addition, the GridView control is bound to an ObjectDataSourc e object
that contains the following:

<asp:ObjectData Source ID="ObjectDataS ource1" runat="server"
DeleteMethod="D eleteActivity" InsertMethod="I nsertActivity"
SelectMethod="G etActivities" TypeName="SoftC ircuits.MediCor p.Activities"
UpdateMethod="U pdateActivity">
<DeleteParamete rs>
<asp:Paramete r Name="activityI d" Type="Int32" />
</DeleteParameter s>
<UpdateParamete rs>
...
</UpdateParameter s>
<SelectParamete rs>
...
</SelectParameter s>
<InsertParamete rs>
...
</InsertParameter s>
</asp:ObjectDataS ource>

I'm trying to understand how some of this information hooks up. When I
click the delete link (and click OK in the confirmation), the
DeleteActivity method of SoftCircuits.Me diCorp.Activiti es does in fact get
called. However, the activityId argument is always 0.

Can anyone help me understand where the ObjectDataSourc e should be getting
this argument value from such that it would represent the id of the record
on the row for which the Delete link was clicked?

The activityId represents the primary key of the table being displayed.

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
Jun 27 '08 #2
Thanks. I seemed to be able to get this working, but I'm still not fully
clear on how this is setup.

The underlying name of the table's primary key is ID. If I set the
DataKeyNames property to ID, then I get the error "could not find a
non-generic method 'DeleteActivity ' that has parameters: activityId, ID."

So I then change the delete parameter name to just ID. And I then get the
error "could not find a non-generic method 'DeleteActivity ' that has
parameters: ID."

Finally, I change the name of the method's argument to ID and it does work.

But so did the DataKeyNames property specify the name of the database's
primary key, the delete parameter name, the method's argument name, or all
three? If all three, as appears to be the case, is there no way to have the
method argument name be different from the actual name of the table's
primary key column?

Just trying to understand this better.

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"S.M. Altaf [MVP]" <sm*****@mNOSPA Msn.comwrote in message
news:7F******** *************** ***********@mic rosoft.com...
Set the GridView's DataKeyNames attribute value to activityId.

--
---------------------------------------------------
S.M. Altaf [MVP]
http://www.mendhak.com/
"Jonathan Wood" <jw***@softcirc uits.comwrote in message
news:Ow******** ******@TK2MSFTN GP06.phx.gbl...
>Greetings,

I have a GridView control. For a couple of reasons, I ended up with a
TemplateFiel d to contain my Edit and Delete links, something like this:

<asp:TemplateFi eld ShowHeader="Fal se">
<EditItemTempla te>
<asp:LinkButt on ID="LinkButton1 " runat="server"
CausesValidati on="True"
CommandName="Up date" Text="Update"></asp:LinkButton>
&nbsp;<asp:Link Button ID="LinkButton2 " runat="server"
CausesValidati on="False"
CommandName="Ca ncel" Text="Cancel"></asp:LinkButton>
</EditItemTemplat e>
<ItemTemplate >
<asp:LinkButt on ID="LinkButton1 " runat="server"
CausesValidati on="False"
CommandName="Ed it" Text="Edit"></asp:LinkButton>
&nbsp;<asp:Link Button ID="lnkDelete" runat="server"
CausesValidati on="false"
CommandName="De lete" Text="Delete"
OnClientClick=" return confirm('Are you sure you want to delete this
record?');" />
</ItemTemplate>

In addition, the GridView control is bound to an ObjectDataSourc e object
that contains the following:

<asp:ObjectDat aSource ID="ObjectDataS ource1" runat="server"
DeleteMethod="D eleteActivity" InsertMethod="I nsertActivity"
SelectMethod="G etActivities" TypeName="SoftC ircuits.MediCor p.Activities"
UpdateMethod="U pdateActivity">
<DeleteParamete rs>
<asp:Paramete r Name="activityI d" Type="Int32" />
</DeleteParameter s>
<UpdateParamete rs>
...
</UpdateParameter s>
<SelectParamete rs>
...
</SelectParameter s>
<InsertParamete rs>
...
</InsertParameter s>
</asp:ObjectDataS ource>

I'm trying to understand how some of this information hooks up. When I
click the delete link (and click OK in the confirmation), the
DeleteActivi ty method of SoftCircuits.Me diCorp.Activiti es does in fact
get called. However, the activityId argument is always 0.

Can anyone help me understand where the ObjectDataSourc e should be
getting this argument value from such that it would represent the id of
the record on the row for which the Delete link was clicked?

The activityId represents the primary key of the table being displayed.

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
Jun 27 '08 #3
The DataKeyNames property of the GridView tells it which fields in the data
that it's dealing with are the primary key fields. I had assumed that yours
was activityID, but it appears that yours is ID.

As for the second question, I can't really tell why changing the method
argument name made any difference at all, because it shouldn't. Do you
continue to get errors if you change the method argument name to something
else? If yes, then the only slightly reasonable explanation that I can
think of is the usage of System.Reflecti on by the GridView to invoke the
Delete method, wherein it specifies the argument value as well as name,
based upon what it has been passed in the DataKeyNames property.

Having said that, I have still seen examples of the ObjectDataSourc e being
used with any arbitrary argument name given to the Delete method.

--
---------------------------------------------------
S.M. Altaf [MVP]
http://www.mendhak.com/
"Jonathan Wood" <jw***@softcirc uits.comwrote in message
news:Or******** ******@TK2MSFTN GP05.phx.gbl...
Thanks. I seemed to be able to get this working, but I'm still not fully
clear on how this is setup.

The underlying name of the table's primary key is ID. If I set the
DataKeyNames property to ID, then I get the error "could not find a
non-generic method 'DeleteActivity ' that has parameters: activityId, ID."

So I then change the delete parameter name to just ID. And I then get the
error "could not find a non-generic method 'DeleteActivity ' that has
parameters: ID."

Finally, I change the name of the method's argument to ID and it does
work.

But so did the DataKeyNames property specify the name of the database's
primary key, the delete parameter name, the method's argument name, or all
three? If all three, as appears to be the case, is there no way to have
the method argument name be different from the actual name of the table's
primary key column?

Just trying to understand this better.

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"S.M. Altaf [MVP]" <sm*****@mNOSPA Msn.comwrote in message
news:7F******** *************** ***********@mic rosoft.com...
>Set the GridView's DataKeyNames attribute value to activityId.

--
---------------------------------------------------
S.M. Altaf [MVP]
http://www.mendhak.com/
"Jonathan Wood" <jw***@softcirc uits.comwrote in message
news:Ow******* *******@TK2MSFT NGP06.phx.gbl.. .
>>Greetings,

I have a GridView control. For a couple of reasons, I ended up with a
TemplateFie ld to contain my Edit and Delete links, something like this:

<asp:TemplateFi eld ShowHeader="Fal se">
<EditItemTempla te>
<asp:LinkButt on ID="LinkButton1 " runat="server"
CausesValidat ion="True"
CommandName="Up date" Text="Update"></asp:LinkButton>
&nbsp;<asp:Link Button ID="LinkButton2 " runat="server"
CausesValidat ion="False"
CommandName="Ca ncel" Text="Cancel"></asp:LinkButton>
</EditItemTemplat e>
<ItemTemplate >
<asp:LinkButt on ID="LinkButton1 " runat="server"
CausesValidat ion="False"
CommandName="Ed it" Text="Edit"></asp:LinkButton>
&nbsp;<asp:Link Button ID="lnkDelete" runat="server"
CausesValidat ion="false"
CommandName="De lete" Text="Delete"
OnClientClick=" return confirm('Are you sure you want to delete this
record?');" />
</ItemTemplate>

In addition, the GridView control is bound to an ObjectDataSourc e object
that contains the following:

<asp:ObjectDa taSource ID="ObjectDataS ource1" runat="server"
DeleteMethod="D eleteActivity" InsertMethod="I nsertActivity"
SelectMethod="G etActivities"
TypeName="Sof tCircuits.MediC orp.Activities"
UpdateMethod="U pdateActivity">
<DeleteParamete rs>
<asp:Paramete r Name="activityI d" Type="Int32" />
</DeleteParameter s>
<UpdateParamete rs>
...
</UpdateParameter s>
<SelectParamete rs>
...
</SelectParameter s>
<InsertParamete rs>
...
</InsertParameter s>
</asp:ObjectDataS ource>

I'm trying to understand how some of this information hooks up. When I
click the delete link (and click OK in the confirmation), the
DeleteActivit y method of SoftCircuits.Me diCorp.Activiti es does in fact
get called. However, the activityId argument is always 0.

Can anyone help me understand where the ObjectDataSourc e should be
getting this argument value from such that it would represent the id of
the record on the row for which the Delete link was clicked?

The activityId represents the primary key of the table being displayed.

Thanks.

--
Jonathan Wood
SoftCircuit s Programming
http://www.softcircuits.com
Jun 27 '08 #4
Yeah, it appears that, no matter what, the objectdatasourc e eventually is
looking for an ID argument in the method.

If I change the method argument name to xID, and also change the
ObjectDataSourc e's delete parameter name to xID, then I get the error that
the method could not be found that takes the arguments xID, ID.

This seems uncharacteristi c of .NET and something I'm having trouble feeling
comfortable with. Again, it is working. But it's still not quite sitting
right with me.

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"S.M. Altaf [MVP]" <sm*****@mNOSPA Msn.comwrote in message
news:98******** *************** ***********@mic rosoft.com...
The DataKeyNames property of the GridView tells it which fields in the
data that it's dealing with are the primary key fields. I had assumed
that yours was activityID, but it appears that yours is ID.

As for the second question, I can't really tell why changing the method
argument name made any difference at all, because it shouldn't. Do you
continue to get errors if you change the method argument name to something
else? If yes, then the only slightly reasonable explanation that I can
think of is the usage of System.Reflecti on by the GridView to invoke the
Delete method, wherein it specifies the argument value as well as name,
based upon what it has been passed in the DataKeyNames property.

Having said that, I have still seen examples of the ObjectDataSourc e being
used with any arbitrary argument name given to the Delete method.

--
---------------------------------------------------
S.M. Altaf [MVP]
http://www.mendhak.com/
"Jonathan Wood" <jw***@softcirc uits.comwrote in message
news:Or******** ******@TK2MSFTN GP05.phx.gbl...
>Thanks. I seemed to be able to get this working, but I'm still not fully
clear on how this is setup.

The underlying name of the table's primary key is ID. If I set the
DataKeyNames property to ID, then I get the error "could not find a
non-generic method 'DeleteActivity ' that has parameters: activityId, ID."

So I then change the delete parameter name to just ID. And I then get the
error "could not find a non-generic method 'DeleteActivity ' that has
parameters: ID."

Finally, I change the name of the method's argument to ID and it does
work.

But so did the DataKeyNames property specify the name of the database's
primary key, the delete parameter name, the method's argument name, or
all three? If all three, as appears to be the case, is there no way to
have the method argument name be different from the actual name of the
table's primary key column?

Just trying to understand this better.

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"S.M. Altaf [MVP]" <sm*****@mNOSPA Msn.comwrote in message
news:7F******* *************** ************@mi crosoft.com...
>>Set the GridView's DataKeyNames attribute value to activityId.

--
---------------------------------------------------
S.M. Altaf [MVP]
http://www.mendhak.com/
"Jonathan Wood" <jw***@softcirc uits.comwrote in message
news:Ow****** ********@TK2MSF TNGP06.phx.gbl. ..
Greetings,

I have a GridView control. For a couple of reasons, I ended up with a
TemplateFiel d to contain my Edit and Delete links, something like this:

<asp:TemplateFi eld ShowHeader="Fal se">
<EditItemTempla te>
<asp:LinkButt on ID="LinkButton1 " runat="server"
CausesValida tion="True"
CommandName="Up date" Text="Update"></asp:LinkButton>
&nbsp;<asp:Link Button ID="LinkButton2 " runat="server"
CausesValida tion="False"
CommandName="Ca ncel" Text="Cancel"></asp:LinkButton>
</EditItemTemplat e>
<ItemTemplate >
<asp:LinkButt on ID="LinkButton1 " runat="server"
CausesValida tion="False"
CommandName="Ed it" Text="Edit"></asp:LinkButton>
&nbsp;<asp:Link Button ID="lnkDelete" runat="server"
CausesValida tion="false"
CommandName="De lete" Text="Delete"
OnClientClick=" return confirm('Are you sure you want to delete
this record?');" />
</ItemTemplate>

In addition, the GridView control is bound to an ObjectDataSourc e
object that contains the following:

<asp:ObjectD ataSource ID="ObjectDataS ource1" runat="server"
DeleteMethod="D eleteActivity" InsertMethod="I nsertActivity"
SelectMethod="G etActivities"
TypeName="So ftCircuits.Medi Corp.Activities "
UpdateMethod="U pdateActivity">
<DeleteParamete rs>
<asp:Paramete r Name="activityI d" Type="Int32" />
</DeleteParameter s>
<UpdateParamete rs>
...
</UpdateParameter s>
<SelectParamete rs>
...
</SelectParameter s>
<InsertParamete rs>
...
</InsertParameter s>
</asp:ObjectDataS ource>

I'm trying to understand how some of this information hooks up. When I
click the delete link (and click OK in the confirmation), the
DeleteActivi ty method of SoftCircuits.Me diCorp.Activiti es does in fact
get called. However, the activityId argument is always 0.

Can anyone help me understand where the ObjectDataSourc e should be
getting this argument value from such that it would represent the id of
the record on the row for which the Delete link was clicked?

The activityId represents the primary key of the table being displayed.

Thanks.

--
Jonathan Wood
SoftCircui ts Programming
http://www.softcircuits.com
Jun 27 '08 #5

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

Similar topics

2
1247
by: Krish | last post by:
Hello Gurus, I have Master GridView & Detail Gridview and following another detail gridview control. On "select" master grid , detail grid shows data, On "Select" No. 1. detail grid, No.2 detail grid shows data, but if there is no data in 1st detail grid, still 2nd grid is showing data from cache. How to overcome this issue. Pl. advise. krish
0
903
by: CSharpguy | last post by:
has anyone been able to sort a gridview without using a sqlobjectdatasource or typed dataset? My problem is that my method to bind my datagrid takes parameterts from dropdowns, then the user clicks go and the grid binds. example: void GetSales(string strLastname { DataSet dsSales;
1
21466
by: mercercreek | last post by:
This one should be easy. Hope someone has a clue. Simple Scenario: Gridview with mulitple rows, each row with a checkbox. The user checks boxes of her choice. Clicks a button on the form (not in the grid). Desired aciton is then taken in response to the button_onclick event relevant to the row in which the checked checkboxes exist. Unfortunate Outcome: Each checkbox returns false for its attribute:checked whether the user has placed a...
0
2250
by: cook.jonathan.m | last post by:
I want to programmatically add a dropdown to each row in a certain column returned to the gridview by my query. I want to do this entirely in behind-code. My gridview tag in the page will have the following code and no more. <asp:GridView ID="gv" runat="server" AutoGenerateColumns="false"> </asp:GridView> Now, I have generated boundfields to add regular data without a
1
4269
by: jobs | last post by:
I've been staring at this and can't explain why it's not working. The grid shows up fine, except the last column, Reset User button does not render??? I checked the codebehind and I am not removing visiblity or disabling anywhere??? Thanks for any help or information.
4
8420
by: nguyenlh | last post by:
i make a gridview and i make a code : delete row in gridview public bool Delete(int id, out string Msg) { Msg = ""; try { SqlServerDb sql = new SqlServerDb();// library connect sql.Connect();
1
1742
by: mghihor | last post by:
Dear GridView Experts! I have problems with GridView when adding a column using TemplateField. I fill GridView1 from a stored procedure. It has a Select statement and returns 14 columns, AutoGenerateColumns="True". When I add two columns manually to be able to start drag and drop, the drag and drop works OK, but in GridView1_PreRender() and GridView1_RowCreated() I loose values of GridView1.Rows.Cells.Text and e.Row.Cells.Text, these are ""....
1
1662
by: Michael | last post by:
I reviewed a couple of tutorials that show how to display totals in the footer of a gridview. My footer shows up blank. Can someone help me. The code is as follows: <%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server">
1
6169
by: k3nz0 | last post by:
Hi All, I have a GridView and inside this GridView I only have one TemplateField. Inside this TemplateField, I have plenty of textboxes. Values of these textboxes are extracted from the database. One of the textboxes is called txt_CarFeatures (this is the ID). Value of this textbox is extracted from the database, using Bind("CarFeatures"). There is no problem populating the value into the textbox. My problem is how to get the value from...
0
8625
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8977
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8841
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7658
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6488
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2997
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2269
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1971
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.