473,405 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Gridview command event args!

Hello,

I am trying to get add a product to a cart from a gridview control when a
button in the gridview is clicked. I have a book on how to do this in
asp.net 2.0 but it is done by specifying the "DataTextField" as the
productID of the product that I want to add. This works but the button
displays the productID as the text instead of "Add to Cart".

What is the best way to get this to work?

Thanks in advance.

J
Nov 19 '05 #1
3 5570
Can anyone help me with this?
<wa********@newsgroups.nospam> wrote in message
news:ex**************@TK2MSFTNGP10.phx.gbl...
Hello,

I am trying to get add a product to a cart from a gridview control when a
button in the gridview is clicked. I have a book on how to do this in
asp.net 2.0 but it is done by specifying the "DataTextField" as the
productID of the product that I want to add. This works but the button
displays the productID as the text instead of "Add to Cart".

What is the best way to get this to work?

Thanks in advance.

J

Nov 19 '05 #2
Hi J,

welcome.
Regarding on the setting additional parameter for the button in GridView
Row, I think the best choice is using a template field ( we can do it from
converting a button field into template field in gridview). In template
field, we can specify additional databinding field in the template like:

=================
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CausesValidation="false" CommandName=""
CommandArgument='<%# Eval("CategoryName") %>'
Text="Button"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
===================

In addition, we can also use the ItemDataBound event and manually store the
value into any other hidden control's attribute (or just in the
GridViewRow.Attributes ) and retrieve back later, e.g:

=================
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drv = e.Row.DataItem as DataRowView;
e.Row.Attributes.Add("myattr", drv[1].ToString());
}
}
==================

we can then retrieve it back through the following code in RowCommand:

=========
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs
e)
{
GridViewRow row = ((Control)e.CommandSource).NamingContainer as
GridViewRow;

Response.Write("<br>myattr: " + row.Attributes["myattr"]);
}
===========

Anyway, there're several means to achieve this, we can use the one we like.
Hope helps.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Reply-To: <wa********@newsgroups.nospam>
| From: <wa********@newsgroups.nospam>
| References: <ex**************@TK2MSFTNGP10.phx.gbl>
| Subject: Re: Gridview command event args!
| Date: Tue, 1 Nov 2005 10:24:39 -0800
| Lines: 22
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Response
| Message-ID: <er**************@TK2MSFTNGP15.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: ip-206.159.118.137.hdiss.net 206.159.118.137
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP15.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:135302
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Can anyone help me with this?
|
|
| <wa********@newsgroups.nospam> wrote in message
| news:ex**************@TK2MSFTNGP10.phx.gbl...
| > Hello,
| >
| > I am trying to get add a product to a cart from a gridview control when
a
| > button in the gridview is clicked. I have a book on how to do this in
| > asp.net 2.0 but it is done by specifying the "DataTextField" as the
| > productID of the product that I want to add. This works but the button
| > displays the productID as the text instead of "Add to Cart".
| >
| > What is the best way to get this to work?
| >
| > Thanks in advance.
| >
| > J
| >
| >
|
|
|

Nov 19 '05 #3
Hi J,

Haven't heard from you. How are you doing on this issue, have you got any
further ideas or does the suggetions in my last reply helps a little? If
there're anything else we can help, please feel free to post here. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| X-Tomcat-ID: 40441496
| References: <ex**************@TK2MSFTNGP10.phx.gbl>
<er**************@TK2MSFTNGP15.phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: st*****@online.microsoft.com (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Wed, 02 Nov 2005 01:59:42 GMT
| Subject: Re: Gridview command event args!
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| Message-ID: <MN**************@TK2MSFTNGXA01.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Lines: 87
| Path: TK2MSFTNGXA01.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:135393
| NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
|
| Hi J,
|
| welcome.
| Regarding on the setting additional parameter for the button in GridView
| Row, I think the best choice is using a template field ( we can do it
from
| converting a button field into template field in gridview). In template
| field, we can specify additional databinding field in the template like:
|
| =================
| <asp:TemplateField ShowHeader="False">
| <ItemTemplate>
| <asp:LinkButton ID="LinkButton1" runat="server"
| CausesValidation="false" CommandName=""
| CommandArgument='<%# Eval("CategoryName") %>'
| Text="Button"></asp:LinkButton>
| </ItemTemplate>
| </asp:TemplateField>
| </Columns>
| </asp:GridView>
| ===================
|
| In addition, we can also use the ItemDataBound event and manually store
the
| value into any other hidden control's attribute (or just in the
| GridViewRow.Attributes ) and retrieve back later, e.g:
|
| =================
| protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs
| e)
| {
| if (e.Row.RowType == DataControlRowType.DataRow)
| {
| DataRowView drv = e.Row.DataItem as DataRowView;
| e.Row.Attributes.Add("myattr", drv[1].ToString());
| }
| }
| ==================
|
| we can then retrieve it back through the following code in RowCommand:
|
| =========
| protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs
| e)
| {
| GridViewRow row = ((Control)e.CommandSource).NamingContainer as
| GridViewRow;
|
| Response.Write("<br>myattr: " + row.Attributes["myattr"]);
| }
| ===========
|
| Anyway, there're several means to achieve this, we can use the one we
like.
| Hope helps.
|
| Thanks,
|
| Steven Cheng
| Microsoft Online Support
|
| Get Secure! www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
|
|
| --------------------
| | Reply-To: <wa********@newsgroups.nospam>
| | From: <wa********@newsgroups.nospam>
| | References: <ex**************@TK2MSFTNGP10.phx.gbl>
| | Subject: Re: Gridview command event args!
| | Date: Tue, 1 Nov 2005 10:24:39 -0800
| | Lines: 22
| | X-Priority: 3
| | X-MSMail-Priority: Normal
| | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| | X-RFC2646: Format=Flowed; Response
| | Message-ID: <er**************@TK2MSFTNGP15.phx.gbl>
| | Newsgroups: microsoft.public.dotnet.framework.aspnet
| | NNTP-Posting-Host: ip-206.159.118.137.hdiss.net 206.159.118.137
| | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP15.phx.gbl
| | Xref: TK2MSFTNGXA01.phx.gbl
| microsoft.public.dotnet.framework.aspnet:135302
| | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| |
| | Can anyone help me with this?
| |
| |
| | <wa********@newsgroups.nospam> wrote in message
| | news:ex**************@TK2MSFTNGP10.phx.gbl...
| | > Hello,
| | >
| | > I am trying to get add a product to a cart from a gridview control
when
| a
| | > button in the gridview is clicked. I have a book on how to do this
in
| | > asp.net 2.0 but it is done by specifying the "DataTextField" as the
| | > productID of the product that I want to add. This works but the
button
| | > displays the productID as the text instead of "Add to Cart".
| | >
| | > What is the best way to get this to work?
| | >
| | > Thanks in advance.
| | >
| | > J
| | >
| | >
| |
| |
| |
|
|

Nov 19 '05 #4

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

Similar topics

0
by: Bandit | last post by:
I'm populating a gridview (called docList) with document info from a network folder like so: Sub Show_Files(ByVal inputDir As String) Dim strFileNamePath As String = inputDir Dim dirInfo As...
3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
3
by: chelsea | last post by:
I am using a GridView control with a ButtonField and receiving 2 row command events for each click of the button. Is there a configuration switch that I can turn that will ensure I only receive...
0
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this...
9
by: mike7510uk | last post by:
Hi, I am using a gridview with a templatefield containing a checkbox. I want to update the database with a 1 or 0 depending on if a checkbox is checked or unchecked (then use the 1 or 0 later on...
1
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some...
2
by: tomh2099 | last post by:
Hi, Hi, I have an ASP.NET 2005 application (using VB) with a GridView control that needs to have the last 5 or 6 rows in Bold or maybe some other special formatting. Most of the rows show...
4
by: glbdev | last post by:
Hi, I posted this question yesterday but didn't get the answer I needed. I am DESPERATE to get this working so I'm re-posting it because I don't think I worded it correctly. I have a GridView...
1
by: =?Utf-8?B?SmFjaw==?= | last post by:
Hi, I have a simple code where I am trying to capture a recordset in a grid veiw using a button click event. Data is connected to sql server 2000. However, I am getting error at the line...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...
0
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...

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.