Link to home
Start Free TrialLog in
Avatar of narmi2
narmi2

asked on

Datagrid (OnSelectedIndexChanged) Problem

Hi

I have a link button which says:
<asp:LinkButton id="lbQuote" runat="server" commandname="select">Quote</asp:LinkButton>

I have a datagrid which says:
onSelectedIndexChanged="getSelected"

And in code behind it says:
Sub getQuoted(ByVal src As Object, ByVal e As EventArgs)
    response.redirect("page1.aspx?id=" & DataGrid1.DataKeys(DataGrid1.SelectedIndex).ToString)
End Sub

What I need now is another link button, next to the existing link button which does something different depending on the row in the datagrid it is in...

For example

Sub getReported(ByVal src As Object, ByVal e As EventArgs)
    response.redirect("page2.aspx?id=" & DataGrid1.DataKeys(DataGrid1.SelectedIndex).ToString)
End Sub

How would I go about doing that?
Avatar of mmarinov
mmarinov

Hello narmi2,

just add the CommandArgument property and assing a value to it
also do the same for the lbQuote
assign both to the getSelected event
and before call Response.Redirect check the value of the

 Dim clickedButton as LinkButton = CType(src, LinkButton)
 if clickedButton.CommandArgument = '' then
.....

Regards,
Martin
ASKER CERTIFIED SOLUTION
Avatar of sabeesh
sabeesh
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of narmi2

ASKER

Thanks

I now have this

        Dim clickedButton As LinkButton = CType(src, LinkButton)

        If clickedButton.CommandArgument = "caQuoted" Then
            Response.Redirect("reply.aspx?t=" & CInt(Request.QueryString("t")) & "&p=" & DataGrid1.DataKeys(DataGrid1.SelectedIndex).ToString)
        Else
            Response.Redirect("report.aspx?t=" & CInt(Request.QueryString("t")) & "&p=" & DataGrid1.DataKeys(DataGrid1.SelectedIndex).ToString)
        End If

and it says:

Specified cast is not valid

when I click one or any of the 2 linkbuttons.
I think I was wrong
You have to use no the onSelectedIndexChanged of the grid but the onclick events of the button
on other hand hte sabeesh solution looks more nice and clear

Martin