Using the SelectedIndexChanged Event in asp.net (vb.net)

Hi,

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


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

Font-Size="Small"
                        PageSize="4" OnPageIndexChanged="DataGrid1_PageIndexChanged"

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

BackColor="#C0FFC0">
                        <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"

BackColor="LightSteelBlue"></HeaderStyle>
                        <Columns>
                              <asp:ButtonColumn CommandName="Select"

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

HeaderText="DateIn"></asp:BoundColumn>
                              <asp:BoundColumn DataField="Customer"

HeaderText="Customer"></asp:BoundColumn>
                              <asp:BoundColumn DataField="JobStatus"

HeaderText="JobStatus"></asp:BoundColumn>
                              <asp:ButtonColumn Text="Solution" ButtonType="PushButton"

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

runat="server" Checked='<%# DataBinder.Eval(Container.DataItem, "Assigned") %>'>
                                          </asp:CheckBox>
                                    </ItemTemplate>
                              </asp:TemplateColumn>
                        </Columns>
                        <PagerStyle Mode="NumericPages"></PagerStyle>
                  </asp:datagrid>



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 vb.net but no luck.

Pls help,
Rgs,

Mehul


meluAsked:
Who is Participating?
 
Amrik27Connect With a Mentor Commented:
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.

Amrik
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.