Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

ButtonField to TemplateField with Button

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Elmo Watson - 04 Feb 2008 17:36 GMT
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?
Milosz Skalecki [MCAD] - 05 Feb 2008 00:43 GMT
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
Signature

Milosz

> I've converted a buttonfield to a TemplateField with a button in it
>
[quoted text clipped - 10 lines]
>
> What am i missing here?
dbelogrlic@gmail.com - 07 Feb 2008 21:02 GMT
On Feb 5, 1:43 am, Milosz Skalecki [MCAD] <mily...@DONTLIKESPAMwp.pl>
wrote:
> Hi Elmo,
>
[quoted text clipped - 46 lines]
>
> > What am i missing here?

Thank you,Milos ....You are MASTER

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.