Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grabbing the item index of a datagrid 2

Status
Not open for further replies.

Modica82

Technical User
Jan 31, 2003
410
GB
Hi all,

I want to add the index of a datagrid to the query string when a button is clicked from a template column in a datagrid. How do i get the current index of a row?

Can i grab that info?

Rob

---------------------------------------
 
You can create a button in a template column
<asp:linkbutton CommandName="RunSomething" Text="RunIt" id="btnRunIt" runat="server"/>
Ensure that the datagrid has
OnItemCommand="dg_ItemCommand"

then the command can get the index-

Private sub dg_ItemCommand(source As Object, e As DataGridCommandEventArgs)

Select e.Commandname
Case "RunSomething"
Dim intIndex as integer = e.Item.ItemIndex
End Select

End Sub


....vwhite

"I used to have a handle on life...then it broke
 
can you not call the selected index? doesnt that associate whenever anything is clicked in that row?

sub itemActionFromTemplate(sender as object, e as eventargs)
dim dgIndex as integer = MyDataGrid.SelectedIndex
'do something else with it
end sub
 
i just tried it and it doesnt in a item select datagrid...sorry
 
Found this way of doing it...

Code:
                <asp:TemplateColumn HeaderText="Client Name" ItemStyle-Wrap="False" ItemStyle-Width="125">
                    <ItemTemplate>
                        <asp:LinkButton runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ClientName") %>'
                            id=lbUser CssClass="hyper" OnCommand=openClient CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ClientID") %>' />
                    </ItemTemplate>
                </asp:TemplateColumn>

    Sub openClient(ByVal sender As Object, ByVal intID As CommandEventArgs)
        Dim link As String = "'userDetail.aspx?clientid=" & intID.CommandArgument & "',""""" & ",""HEIGHT=520,WIDTH=900,scrollbars=yes"""
        message.Text = "<script language='javascript'>window.open(" & link & ")</script>"
    End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top