How to get row values in column ASPxgridview ?

CheeseFaiy 1 Reputation point
2022-09-26T07:30:30.527+00:00

Hello, I have a gridview that shows the Benefit History lists.

The code is like this :

<dx:ASPxGridView ID="grdBenefitsHistory" runat="server" CssClass="table table-condensed" DataSourceID="getListBenefits" Width="100%" KeyFieldName="id">  
                                <Columns>  
                                    <dx:GridViewDataTextColumn Caption="ID" FieldName="id" VisibleIndex="0" ReadOnly="true" Visible="false"/>  
                                    <dx:GridViewDataTextColumn Caption="Amount" FieldName="Amount" VisibleIndex="1" ReadOnly="true"/>  
                                    <dx:GridViewDataTextColumn Caption="Type" FieldName="type_name" VisibleIndex="2" ReadOnly="true"/>  
                                    <dx:GridViewDataTextColumn Caption="Effcetive Date" FieldName="start_date" VisibleIndex="3" ReadOnly="true"/>  
                                    <dx:GridViewDataTextColumn Caption="End Date" FieldName="end_date" VisibleIndex="4" />  
                                    <dx:GridViewDataTextColumn Caption="Updated By" FieldName="updated_by" VisibleIndex="5" ReadOnly="true"/>  
                                    <dx:GridViewDataTextColumn Caption="Updated Date" FieldName="updated_date_time" VisibleIndex="6" ReadOnly="true"/>                            
                                    <dx:GridViewCommandColumn ShowEditButton="true" VisibleIndex="7" ButtonType="Image" Caption="Edit" Width="50px">  
                                        <CustomButtons>  
                                            <dx:GridViewCommandColumnCustomButton ID="Edit">  
                                                <Image Url="editButton.png" Width="12px"></Image>  
                                            </dx:GridViewCommandColumnCustomButton>  
                                        </CustomButtons>  
                                    </dx:GridViewCommandColumn>  
                                    <dx:GridViewCommandColumn ShowDeleteButton="true" VisibleIndex="8" ButtonType="Image" Caption="Delete" Width="50px">  
                                        <CustomButtons>  
                                            <dx:GridViewCommandColumnCustomButton ID="Delete">  
                                                <Image Url="trash.png" Width="12px"></Image>  
                                            </dx:GridViewCommandColumnCustomButton>  
                                        </CustomButtons>  
                                    </dx:GridViewCommandColumn>  
                                </Columns>  
                                <Settings ShowGroupPanel="True" ShowPreview="True" ShowFilterRow="True" ShowFilterRowMenuLikeItem="True" />  
                                <Settings GridLines="Horizontal" />  
                                <SettingsBehavior AllowSelectByRowClick="true" ColumnResizeMode="Control"/>  
</dx:ASPxGridView>  
<asp:ObjectDataSource ID="getListBenefits" runat="server" SelectMethod="getBenefitsByEmpno" TypeName="clsBenefit_dal">  
                                <SelectParameters>  
                                    <asp:ControlParameter Name="strEmpNo" ControlID="lblEmpNo" PropertyName="Text" />  
                                </SelectParameters>  
</asp:ObjectDataSource>  

The gridview is fine. My problem is how can I get row values on column 'ID' when I click button edit ? I have a function to get all the rows values in each column one you click the edit button. Here is the function :

    Private Function selectBenefitByID(ByVal intID As Integer) As DataTable  
        Dim dt As New DataTable  
        Dim getData As String = " SELECT A.`id`, A.`Type`,A.`Pay_Stub_Type_Id`,SUBSTRING(A.`Amount`, 1, 7) AS 'Amount', " & _  
                                " DATE_FORMAT(A.`start_date`, '%Y-%m-%d') AS 'start_date', DATE_FORMAT(A.`end_date`, '%Y-%m-%d') AS 'end_date', B.`Type_Name`" & _  
                                " FROM payroll_employee_benefits A" & _  
                                " LEFT JOIN payroll_pay_stub_type B ON A.`Type` = B.`Id`" & _  
                                " WHERE  A.`id` = @id AND A.`deleted` = 0 "  
        myconn.AddParameter("@id", MySqlDbType.Int32)  
        myconn.SetParameter("@id", intID)  
        Try  
            myconn.OpenConnection()  
            myconn.FillDataTable(dt, getData)  
            myconn.CloseConnection()  
            myconn.ClearAllParameter()  
            If dt.Rows.Count > 0 Then  
                txtAmount.Text = dt.Rows(0).Item("Amount").ToString  
                cmbType.Text = dt.Rows(0).Item("Type_Name").ToString  
                datepickerFrom.Text = dt.Rows(0).Item("start_date").ToString  
                datepickerto.Text = dt.Rows(0).Item("end_date").ToString  
                lblHiddenId.Text = dt.Rows(0).Item("id").ToString  
                txtAmount.ReadOnly = True  
                datepickerFrom.ReadOnly = True  
                cmbType.ReadOnly = True  
                btnAdd.Visible = False  
                btnUpdate.Visible = True  
            End If  
        Catch ex As Exception  
            myconn.CloseConnection()  
            myconn.ClearAllParameter()  
            DisplayMessage("error", "Info", "Something went wrong. Please inform IT to solve this.")  
        End Try  
        Return dt  
    End Function  

So, my question is how can I get the value for parameter ID in the ASPxgridview in function 'selectBenefitByID'.

I call the 'selectBenefitByID' function in gridview.custombuttoncallback handler like this :

    Protected Sub grdBenefitsHistory_CustomButtonCallback(sender As Object, e As ASPxGridViewCustomButtonCallbackEventArgs) Handles grdBenefitsHistory.CustomButtonCallback  
        If e.ButtonID = "Edit" Then  
            Dim id As Integer = Convert.ToInt32(grdBenefitsHistory.GetRowValues(grdBenefitsHistory.FocusedRowIndex, "id"))  // my problem is here   
            selectBenefitByID(id)  // how can i get the id values here ?   
        End If  
    End Sub  

NOTE : I use ASPxGridView Instead of asp:gridview

Developer technologies VB
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.