473,396 Members | 1,914 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,396 software developers and data experts.

ButtonField to TemplateField with Button

I've converted a buttonfield to a TemplateField with a button in it

Previously, in the Rowcommand, to identify the row when the ButtonField was
clicked, I had this code:

Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = MyGrid.Rows(index)

However, with the new TemplateField (with a button in the TemplateField), in
the RowCommand, it does not understand 'e.CommandArgument'

I get the error that the "input string was not in the correct format"

What am i missing here?
Feb 4 '08 #1
2 10391
Hi Elmo,

ButtonField automatically puts the index to CommandArgument property of the
button. Now, because you changed it to TemplateField you are responsible for
binding the value manually yourself:

<asp:GridView runat="server" ID="MyGrid" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button runat="server" ID="btn"
CommandName="MyCustomCommand"
CommandArgument='<%# Container.DataItemIndex
%>' Text="Click Me" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

And the vb.net code behind:

Protected Sub MyGrid_RowCommand(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs ) _
Handles MyGrid.RowCommand

If e.CommandName = "MyCustomCommand" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = MyGrid.Rows(index)
End If

End Sub

Hope it helps
--
Milosz
"Elmo Watson" wrote:
I've converted a buttonfield to a TemplateField with a button in it

Previously, in the Rowcommand, to identify the row when the ButtonField was
clicked, I had this code:

Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = MyGrid.Rows(index)

However, with the new TemplateField (with a button in the TemplateField), in
the RowCommand, it does not understand 'e.CommandArgument'

I get the error that the "input string was not in the correct format"

What am i missing here?
Feb 5 '08 #2
On Feb 5, 1:43 am, Milosz Skalecki [MCAD] <mily...@DONTLIKESPAMwp.pl>
wrote:
Hi Elmo,

ButtonField automatically puts the index to CommandArgument property of the
button. Now, because you changed it to TemplateField you are responsible for
binding the value manually yourself:

<asp:GridView runat="server" ID="MyGrid" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button runat="server" ID="btn"
CommandName="MyCustomCommand"
CommandArgument='<%# Container.DataItemIndex
%>' Text="Click Me" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

And the vb.net code behind:

Protected Sub MyGrid_RowCommand(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs ) _
Handles MyGrid.RowCommand

If e.CommandName = "MyCustomCommand" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = MyGrid.Rows(index)
End If

End Sub

Hope it helps
--
Milosz

"Elmo Watson" wrote:
I've converted a buttonfield to a TemplateField with a button in it
Previously, in the Rowcommand, to identify the row when the ButtonField was
clicked, I had this code:
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = MyGrid.Rows(index)
However, with the new TemplateField (with a button in the TemplateField), in
the RowCommand, it does not understand 'e.CommandArgument'
I get the error that the "input string was not in the correct format"
What am i missing here?
Thank you,Milos ....You are MASTER
Feb 7 '08 #3

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

Similar topics

1
by: Edwin Knoppert | last post by:
I post this again, no answer before. During the beta version it worked, the same code does no longer work in the new release. I have a simple gridview with ButtonField, the button deletes a...
3
by: jhaidon | last post by:
Hi everybody, I want to fill in a GridView with a dataset. So I created the list of fields that I want to see in the gridview. And I added a column (in first position in the gridview) as a...
3
by: GaryDean | last post by:
I have a button field in a gridview defined as follows: <asp:ButtonField ButtonType="Button" CommandName="AcceptOrder" Text="Accept Whole Order"> <ControlStyle Font-Size="X-Small" />...
0
by: mesut | last post by:
hit there, I have a problem getting the rownumbers when I use the template field <asp:button control. I don't get the rownumbers when I use this control. When I use a buttonfield control then I...
1
by: JB | last post by:
I'm dynamically creating a Gridview object and filling it with contents from an ArrayList as follows: GridView2.AutoGenerateColumns = true; GridView2.DataSource = ArrayListObject;...
0
by: jobs | last post by:
My image buttons show up fine, but that last Button (ResetUser) does not - only the header. I've attempted to put it first, but it did not help. My codebehind is doing nothing fancy. The button...
1
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...
1
by: Elmo Watson | last post by:
I know how to add a confirmation or an AJAX extender to a regular button, but is there any way to add a confirm (yes/no) to a ButtonField in a Gridview?
1
by: ravitunk | last post by:
Hello, I have a GridView with the following columns. <asp:GridView ID="myGridView" runat="server" AutoGenerateColumns="False"/> <Columns> <asp:BoundField DataField="name" HeaderText="Name"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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,...
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.