• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 501
  • Last Modified:

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

0
kdeutsch
Asked:
kdeutsch
  • 2
  • 2
1 Solution
 
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
 
kdeutschAuthor Commented:
Ok got thanks for the help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now