locked
ASp Datagrid Viewer RRS feed

  • Question

  • User-1996252179 posted

    I have a data grid control in ASPX and I'm having trouble getting it to do a post back and hit the selected index changed. 

    vb Code:

     Protected Sub dgvLookUp_SelectedIndexChanged(sender As Object, e As EventArgs) Handles dgvLookUp.SelectedIndexChanged
            Try
                'todo Show Image in pbImagePreview
                Dim OrderNo As String = dgvLookUp.SelectedItem.Cells(0).Text
                Dim Sku As String = dgvLookUp.SelectedItem.Cells(1).Text
                Dim TotalItems As String = dgvLookUp.SelectedItem.Cells(2).Text
                Dim PaperTrim As String = dgvLookUp.SelectedItem.Cells(3).Text
                Dim DueDate As String = dgvLookUp.SelectedItem.Cells(4).Text
                Dim ShippingAddressee As String = dgvLookUp.SelectedItem.Cells(5).Text
                Dim ProductionStatus As String = dgvLookUp.SelectedItem.Cells(6).Text
    
                Build_Labels(OrderNo, Sku, ShippingAddressee, DueDate, TotalItems, PaperTrim, ProductionStatus)
            Catch ex As Exception
    
            End Try
        End Sub

    Markup:

    <asp:DataGrid ID="dgvLookUp" runat="server" Width="100%" Visible="False" SelectedIndex="0" AutoGenerateColumns="False">
                                <Columns>
                                    <asp:BoundColumn DataField="OrderNo" HeaderText="OrderNo" ReadOnly="True"></asp:BoundColumn>
                                    <asp:BoundColumn DataField="SKU" HeaderText="SKU" ReadOnly="True"></asp:BoundColumn>
                                    <asp:BoundColumn DataField="TotalItems" HeaderText="TotalItems" ReadOnly="True"></asp:BoundColumn>
                                    <asp:BoundColumn DataField="PaperTrim" HeaderText="PaperTrim" ReadOnly="True"></asp:BoundColumn>
                                    <asp:BoundColumn DataField="DueDate" HeaderText="DueDate" ReadOnly="True"></asp:BoundColumn>
                                    <asp:BoundColumn DataField="ShippingAddressee" HeaderText="Name" ReadOnly="True"></asp:BoundColumn>
                                    <asp:BoundColumn DataField="ProductionStatus" HeaderText="Status" ReadOnly="True"></asp:BoundColumn>
                                </Columns>
                                <SelectedItemStyle BackColor="Silver" />
                            </asp:DataGrid>

    I just need it to hit that selected in dex changed event on back end when the user selects a different row 

    Monday, December 23, 2019 1:38 PM

Answers

  • User288213138 posted

    Hi mholmes34,

    I just need it to hit that selected in dex changed event on back end when the user selects a different row 

    If you want to fire the SelectedIndexChanged event, you should add a select ButtonColumn.

    <asp:DataGrid ID="dgvLookUp" runat="server" Width="100%" Visible="true" SelectedIndex="0" OnSelectedIndexChanged="dgvLookUp_SelectedIndexChanged" AutoGenerateColumns="False">
                    <Columns>
                        <asp:ButtonColumn Text="Select" CommandName="Select" />
                        <asp:BoundColumn DataField="OrderNo" HeaderText="OrderNo" ReadOnly="True"></asp:BoundColumn>
                        <asp:BoundColumn DataField="SKU" HeaderText="SKU" ReadOnly="True"></asp:BoundColumn>
                        <asp:BoundColumn DataField="TotalItems" HeaderText="TotalItems" ReadOnly="True"></asp:BoundColumn>
                        <asp:BoundColumn DataField="PaperTrim" HeaderText="PaperTrim" ReadOnly="True"></asp:BoundColumn>
                        <asp:BoundColumn DataField="DueDate" HeaderText="DueDate" ReadOnly="True"></asp:BoundColumn>
                        <asp:BoundColumn DataField="ShippingAddressee" HeaderText="Name" ReadOnly="True"></asp:BoundColumn>
                        <asp:BoundColumn DataField="ProductionStatus" HeaderText="Status" ReadOnly="True"></asp:BoundColumn>
                        
                    </Columns>
                    <SelectedItemStyle BackColor="Silver" />
                </asp:DataGrid>
    
    
     Protected Sub dgvLookUp_SelectedIndexChanged(sender As Object, e As EventArgs) Handles dgvLookUp.SelectedIndexChanged
            Try
                'todo Show Image in pbImagePreview
                Dim OrderNo As String = dgvLookUp.SelectedItem.Cells(0).Text
                Dim Sku As String = dgvLookUp.SelectedItem.Cells(1).Text
                Dim TotalItems As String = dgvLookUp.SelectedItem.Cells(2).Text
                Dim PaperTrim As String = dgvLookUp.SelectedItem.Cells(3).Text
                Dim DueDate As String = dgvLookUp.SelectedItem.Cells(4).Text
                Dim ShippingAddressee As String = dgvLookUp.SelectedItem.Cells(5).Text
                Dim ProductionStatus As String = dgvLookUp.SelectedItem.Cells(6).Text
               Response.Write(OrderNo + Sku + TotalItems + PaperTrim + DueDate + ShippingAddressee + ProductionStatus);
            Catch ex As Exception
    
            End Try
        End Sub

    The result:

    Best regards,

    Sam

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 24, 2019 2:22 AM

All replies

  • User288213138 posted

    Hi mholmes34,

    I just need it to hit that selected in dex changed event on back end when the user selects a different row 

    If you want to fire the SelectedIndexChanged event, you should add a select ButtonColumn.

    <asp:DataGrid ID="dgvLookUp" runat="server" Width="100%" Visible="true" SelectedIndex="0" OnSelectedIndexChanged="dgvLookUp_SelectedIndexChanged" AutoGenerateColumns="False">
                    <Columns>
                        <asp:ButtonColumn Text="Select" CommandName="Select" />
                        <asp:BoundColumn DataField="OrderNo" HeaderText="OrderNo" ReadOnly="True"></asp:BoundColumn>
                        <asp:BoundColumn DataField="SKU" HeaderText="SKU" ReadOnly="True"></asp:BoundColumn>
                        <asp:BoundColumn DataField="TotalItems" HeaderText="TotalItems" ReadOnly="True"></asp:BoundColumn>
                        <asp:BoundColumn DataField="PaperTrim" HeaderText="PaperTrim" ReadOnly="True"></asp:BoundColumn>
                        <asp:BoundColumn DataField="DueDate" HeaderText="DueDate" ReadOnly="True"></asp:BoundColumn>
                        <asp:BoundColumn DataField="ShippingAddressee" HeaderText="Name" ReadOnly="True"></asp:BoundColumn>
                        <asp:BoundColumn DataField="ProductionStatus" HeaderText="Status" ReadOnly="True"></asp:BoundColumn>
                        
                    </Columns>
                    <SelectedItemStyle BackColor="Silver" />
                </asp:DataGrid>
    
    
     Protected Sub dgvLookUp_SelectedIndexChanged(sender As Object, e As EventArgs) Handles dgvLookUp.SelectedIndexChanged
            Try
                'todo Show Image in pbImagePreview
                Dim OrderNo As String = dgvLookUp.SelectedItem.Cells(0).Text
                Dim Sku As String = dgvLookUp.SelectedItem.Cells(1).Text
                Dim TotalItems As String = dgvLookUp.SelectedItem.Cells(2).Text
                Dim PaperTrim As String = dgvLookUp.SelectedItem.Cells(3).Text
                Dim DueDate As String = dgvLookUp.SelectedItem.Cells(4).Text
                Dim ShippingAddressee As String = dgvLookUp.SelectedItem.Cells(5).Text
                Dim ProductionStatus As String = dgvLookUp.SelectedItem.Cells(6).Text
               Response.Write(OrderNo + Sku + TotalItems + PaperTrim + DueDate + ShippingAddressee + ProductionStatus);
            Catch ex As Exception
    
            End Try
        End Sub

    The result:

    Best regards,

    Sam

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 24, 2019 2:22 AM
  • User-1996252179 posted

    thank you very much, worked perfectly 

    Monday, December 30, 2019 5:32 PM