• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 955
  • Last Modified:

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


0
melu
Asked:
melu
1 Solution
 
Amrik27Commented:
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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now