?
Solved

Datagrid (OnSelectedIndexChanged) Problem

Posted on 2007-08-06
4
Medium Priority
?
975 Views
Last Modified: 2013-11-05
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?
0
Comment
Question by:narmi2
  • 2
4 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 19638533
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
0
 
LVL 8

Accepted Solution

by:
sabeesh earned 2000 total points
ID: 19638616
why cant you add your redirect code in aspx page itself. try something like this.

 <ItemTemplate>
                                <asp:HyperLink runat="server" NavigateUrl='<%# "~/Details.aspx?RID=" + DataBinder.Eval(Container.DataItem, "RegNo")%>' Text='<%# DataBinder.Eval(Container.DataItem, "LastName") %>'></asp:HyperLink>
                            </ItemTemplate>
0
 
LVL 1

Author Comment

by:narmi2
ID: 19638649
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.
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 19638709
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
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Loops Section Overview
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question