473,776 Members | 1,529 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 1808
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
1252
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
906
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
21472
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
2261
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
4276
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
8425
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
1744
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
1664
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
6178
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
10289
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10061
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
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8952
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...
0
6722
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();...
0
5493
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
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
3622
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2860
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.