jeudi 18 mai 2017

How to show CheckBox in the GridView dynamically?

I have a GridView in which I want to show the CheckBox visible to only those rows whose status(column name)='sent' otherwise not.

aspx

<asp:templatefield HeaderText="Cancel SO Line Item">
    <itemtemplate>
    <asp:checkbox ID="cbSOCan" CssClass="gridCB" runat="server"></asp:checkbox>
    </itemtemplate>
    </asp:templatefield>

Code

Protected Sub btnCancelItem_Click(sender As Object, e As EventArgs) Handles btnCancelItem.Click 
    For Each gvrow As GridViewRow In gvPOItems.Rows
        Dim chkdelte As CheckBox = DirectCast(gvrow.FindControl("cbSOCan"), CheckBox)
        If chkdelte.Checked Then
            ' gvAdditionalArea.Rows(rowIndex).Cells(0).Text()
            Dim ItemNumber As Int32 = Convert.ToInt32(gvrow.Cells(0).Text())
            Queries.CancelSOlineItem(ItemNumber, txtPONumber.Text)
            gvrow.Cells(0).Text() = "Cancelled"
        End If
    Next
    ' gvPOItems.DataBind()
End Sub

 Protected Sub gvPOItems_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvPOItems.RowDataBound
    Dim lblStatus As Label = DirectCast(e.Row.FindControl("lblStatus"), Label)
    If lblStatus.Text = "Sent" Then  
        e.Row.Cells(1).Visible = True
    Else
        e.Row.Cells(1).Visible = False
    End If
End Sub

grid




Aucun commentaire:

Enregistrer un commentaire