Getting a gridview's row index on command

D

David Lozzi

Howdy,

I have a gridview with a linkbutton in a template column (code is below).
When the linkbutton is clicked i want to display a little confirm right in
the gridview to confirm deleting the row. I tried using the following to
grab the index, which appears to work on command columns, but not with
buttons in a template? is this true? or am i missing something. how do I get
the row index? Its returning the ID of the record, not the index of the row.
THANKS!

David Lozzi


Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewCommandEventArgs) Handles
GridView1.RowCommand

Dim rowID As Integer = Convert.ToInt32(e.CommandArgument) 'THIS
DOESN'T WORK
If e.CommandName = "Delete1" Then
Dim lbDel As LinkButton =
GridView1.Rows(rowID).FindControl("lbDelete")
Dim div As HtmlGenericControl =
GridView1.Rows(rowID).FindControl("confirm")
lbDel.Visible = False
div.Visible = True
ElseIf e.CommandName = "Cancel1" Then
Dim lbDel As LinkButton =
GridView1.Rows(rowID).FindControl("lbDelete")
Dim div As HtmlGenericControl =
GridView1.Rows(rowID).FindControl("confirm")
lbDel.Visible = True
div.Visible = False
ElseIf e.CommandName = "Confirm1" Then
Dim lblLID As Label =
GridView1.Rows(rowID).FindControl("lblListID")
Dim listID As Integer = lblLID.Text
sdsLists.DeleteCommand = "DELETE FROM [tblEmailLists] WHERE ID =
" & listID & ""
sdsLists.Delete()
End If
End Sub


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="sdsLists">
<Columns>
<asp:TemplateField HeaderText="ID" SortExpression="ID"
Visible="False">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Eval("ID") %>'></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Lists"
SortExpression="strListName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("strListName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# "~/salesrep/editlist.aspx?id=" & Eval("ID") %>'
Text='<%# Eval("strListName") %>'></asp:HyperLink>
</ItemTemplate>
<ItemStyle Wrap="False" />
</asp:TemplateField>
<asp:BoundField DataField="intSalesRep" HeaderText="intSalesRep"
SortExpression="intSalesRep"
Visible="False" />
<asp:TemplateField HeaderText="# Dealers"
SortExpression="Total">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%#
Bind("Total") %>'></asp:TextBox>
</EditItemTemplate>
<HeaderStyle Wrap="False" />
<ItemTemplate>
<div align="center"><asp:Label ID="Label2"
runat="server" Text='<%# Bind("Total") %>'></asp:Label></div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbDelete" runat="server"
CommandName="Delete1">Delete</asp:LinkButton><div
runat="server" id="confirm" visible="false"><asp:Label ID="Label1"
runat="server"
CssClass="required" Text="Are you sure you want
to delete this list? Note that your dealers will NOT be
deleted."></asp:Label>
<asp:LinkButton ID="lbConfirm" runat="server"
CommandName="Confirm1">Yes</asp:LinkButton>
<asp:LinkButton ID="lbCancel" runat="server"
CommandName="Cancel1">No</asp:LinkButton>
<asp:Label ID="lblListID" runat="server"
Text='<%# Bind("ID") %>' Visible="False"></asp:Label></div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top