get value of linkbuttonID on gridview commandname

What I originally had where buttons but having trouble hidding them so I cahnged to templates with buttons so I could hide, no problem but now what I need to do is be able to get the datakey values for the commands or get the databind ID, I put into the gridview to do work with command.  how Can I get this for template linkbuttons, it always gives me an error on this with template button
Input string was not in a correct format.
 Dim row As Integer = Convert.ToInt32(e.CommandArgument)

  but I need that in ther for my last button that I don't want to make a template button unless I can pass data through the commandname.

Protected Sub myGridViewOut_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles myGridViewOut.RowCommand
        Dim row As Integer = Convert.ToInt32(e.CommandArgument)

        If (e.CommandName = "Issues") Then
            Dim Id As Integer = myGridViewOut.DataKeys(row).Values("intSRPAttendId").ToString
            Dim SSN As Integer = myGridViewOut.DataKeys(row).Values("strSSN").ToString

            sql = "Select q.strUnitTask, ed.strData, ed.strRemarks, ed.strDocDate From tblSRPEventData as ed INNER JOIN tblSRPQuestion as q on q.intQuestionId = ed.intQuestionId where intAnswer = 1 AND " _
                & "intPersonnelId = '" & SSN & "'"

            myDataTable = New DataTable
            myDataTable = getData(sql)

            If myDataTable.Rows.Count = Nothing Then
                ScriptManager.RegisterClientScriptBlock(Page, GetType(Page), "OpenWindow", "AddPersonnel();", True)
            Else
                myGridProblems.DataSource = myDataTable
                myGridProblems.DataBind()
                pnlProblems_ModalPopupExtender.Show()
            End If
        End If


        If (e.CommandName = "Del") Then
            Dim Id As Integer = myGridViewOut.DataKeys(row).Values("intSRPAttendId").ToString
            Dim SSN As Integer = myGridViewOut.DataKeys(row).Values("strSSN").ToString

            sql = "Update tblSRPAttendance set bitActive = 0, bitCancel = 1 where intSRPAttendID = " & id & ";Delete from tblSRPEventData where intPersonnelId = " & SSN
            insertUpdateDelete(sql)

            FillGridview()
        End If

    End Sub

Open in new window

kdeutschAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MlandaTCommented:
can you show how you are creating the gridview in the aspx page?
0
kdeutschAuthor Commented:
<td><asp:GridView ID="myGridViewOut" runat="server" Font-Size="12" HeaderStyle-HorizontalAlign="Center" BorderWidth="1px" CellPadding="6" GridLines="Both"
                                                                 BorderColor="#404040" Font-Names="Veranda,arial,sans-serif" AutoGenerateColumns="false" CellSpacing="0" RowStyle-HorizontalAlign="Center" Width="100%"
                                                                DataKeyNames="intSRPAttendId, strSSN" AllowPaging="true" PageSize="20"><AlternatingRowStyle BackColor="#b0c4de" /><HeaderStyle Font-Bold="true" ForeColor="White" BackColor="SteelBlue" />
                                                                    <Columns>
                                                                        <asp:BoundField DataField="strFullname" HeaderText="Name" />
                                                                        <asp:BoundField DataField="DateIn" HeaderText="StartTime" />
                                                                        <asp:BoundField DataField="Dental" HeaderText="Dental" />
                                                                        <asp:BoundField DataField="Medical" HeaderText="Medical" />
                                                                        <asp:BoundField DataField="Admin" HeaderText="Admin" />
                                                                     <asp:TemplateField HeaderText="Issues">
                                                                        <ItemTemplate>
                                                                            <asp:LinkButton ID="lnkIssue" runat="server" CommandName="Issues" Text='<%#Bind("strSSN") %> Issues'></asp:LinkButton>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateField>
                                                                    <asp:TemplateField HeaderText="CheckOut">
                                                                        <ItemTemplate>
                                                                            <asp:LinkButton ID="lnkCheckOut" runat="server" CommandName="CheckOut">Check Out</asp:LinkButton>
                                                                        </ItemTemplate>
                                                                    </asp:TemplateField>
                                                                    <asp:ButtonField ButtonType="Link" CommandName="Del" HeaderText="Cancel" Text="Cancel" />
                                                                    </Columns>
                                                                </asp:GridView>
0
MlandaTCommented:
CommandArgument
if you want to access the commandargument, then you need to add a CommandArgument to the Cancel button:

    <asp:ButtonField ButtonType="Link" CommandName="Del" HeaderText="Cancel" Text="Cancel" />

Open in new window


should be:

  <asp:ButtonField ButtonType="Link" CommandName="Del" HeaderText="Cancel" Text="Cancel" CommandArgument='<%# Eval("intSRPAttendId") %>'/>

Open in new window


that way, in your code when you access the

sql = "Update tblSRPAttendance set bitActive = 0, bitCancel = 1 where intSRPAttendID = " & e.CommandArgument

dataKeys
however, I also observe that you want to access several values and hence the dataKeys becomes very handy. However, in order to use this:

 Dim row As Integer = Convert.ToInt32(e.CommandArgument)

Open in new window


you need to set the command argument to the RowIndex for each button, in the databound event... a simpler way to get the row index would be to just change that line above to this:

Dim gridrow As GridViewRow = TryCast(TryCast(e.CommandSource, WebControl).NamingContainer, GridViewRow)
Dim row As Long = gridrow.RowIndex

Open in new window


You can read this for more discussion on this: http://www.west-wind.com/weblog/posts/88462.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kdeutschAuthor Commented:
Ok got thanks for the help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.