Using the SelectedIndexChanged Event in (

Posted on 2005-05-07
Last Modified: 2012-08-14

I am trying to use (in I have a simple grid.
Here's the code:

<asp:datagrid id="DataGrid1" runat="server" Height="148px" Width="683px" BorderColor="Aqua"

                        PageSize="4" OnPageIndexChanged="DataGrid1_PageIndexChanged"

                        AllowPaging="True" ForeColor="Blue" AutoGenerateColumns="False"

                        <SelectedItemStyle BackColor="#FF80FF"></SelectedItemStyle>
                        <AlternatingItemStyle Font-Size="Smaller" Font-Names="Gill Sans"

Wrap="False" BackColor="Beige"></AlternatingItemStyle>
                        <ItemStyle Font-Size="Smaller" Font-Names="Verdana"></ItemStyle>
                        <HeaderStyle Font-Names="Arial" HorizontalAlign="Left"

                              <asp:ButtonColumn CommandName="Select"

HeaderText="Ticket" DataTextField="Ticket" />
                              <asp:BoundColumn DataField="DateIn"

                              <asp:BoundColumn DataField="Customer"

                              <asp:BoundColumn DataField="JobStatus"

                              <asp:ButtonColumn Text="Solution" ButtonType="PushButton"

HeaderText="Solution Details"></asp:ButtonColumn>
                                    <HeaderStyle Width="1cm"></HeaderStyle>
                                          <asp:CheckBox id=chkAssigned

runat="server" Checked='<%# DataBinder.Eval(Container.DataItem, "Assigned") %>'>
                        <PagerStyle Mode="NumericPages"></PagerStyle>

so basically 6 columns - where the first column is a hyperlink. I want when I click on this

hyperlink to be able to open another web page.

Therefore i have the following code:

    Public Sub DataGrid1_SelectedIndexChanged(ByVal sender As Object, ByVal e As

System.EventArgs) Handles DataGrid1.SelectedIndexChanged

    Dim MyClassSubRoutine As New classSubroutines()
    Dim str As String

    Dim myDataGridItem As DataGridItem
    Dim chkSelected As Button

    chkSelected = CType(DataGrid1.Items(DataGrid1.SelectedIndex).FindControl("Select"), Button)

    ' .... DO SOMETHING

End Sub

However my problem is that chkSelected doesn't get a value. Get "nothing".

I have tried to search for code sample for but no luck.

Pls help,


Question by:melu
    1 Comment
    LVL 1

    Accepted Solution

    I suggest that you take the selected value in a boolean variable and then continue further processing. There seems to be a problem in type casting

    I am sure this will solve your problem.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    INTRODUCTION We all know how to code. But at times you simply want to insert a common code block into your existing code and amend it as per your requirements. This tool not only saves you time but also saves you the pain of typing it all out aga…
    This is about my first experience with programming Arduino.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now