[RESOLVED] Avoid loding data when user unselect

I have checkbox control in Gridview when i selected checkbox entire row will be loaded into corresponding Textboxes, up to here every thing fine when i unchecked again entire row is populating/loading into corresponding Textboxes i dont want to be happen this when i unchecked data should not be loaded.

Anothere one is if i checked "A" record earlier, simulataniously when i checked "B" record "A" record should be un checked automatically but for me it is not happening both records are checked.

how can i acheive above to please help,Thanks

Gridview with checkbox

<asp:GridView ID="GVStatus" runat="server" CellPadding="3" ForeColor="#333333"
            GridLines="Vertical" Height="16px" Width="180px"  AutoGenerateColumns="false"
            EnableModelValidation="True" style="margin-top: 0px" Font-Size="Medium"
                   ToolTip="List of Jobs  from the Database">
             <RowStyle BackColor="#EFF3FB" />
             <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
             <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
             <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
             <HeaderStyle  BackColor="#507CD1"  Width="50px" Font-Bold="True" ForeColor="White" />
             <EditRowStyle BackColor="#2461BF" />
             <AlternatingRowStyle BackColor="White" />
             <Columns>
                 <asp:TemplateField>
                     <ItemTemplate>
                         <asp:CheckBox ID="chkSelect" runat="server" AutoPostBack="true" QuotesKey='<%#Eval("WONumber").ToString() %>' OnCheckedChanged="chkSelect_CheckedChanged"  />
                     </ItemTemplate>
                 </asp:TemplateField>
 </Columns>


 

Hi,

 

Show us your  chkSelect_CheckedChanged method.


Protected Sub chkSelect_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim indx As Integer
        Dim connectionString As String = "Database=pjt;" & "Data Source=localhost;" & "User Id=root;Password=prasad123"
        Dim query As String = "Select WONumber,PartNumber,Rev,customer,CRep,AEng,Orderqty,PReceived,FabDue,FabComp,AssyDue,AssyComp,TestDue,TestComp,Notes,Shippedqty,status from status"
        'Dim query As String = "Select partnumber from status"
        Dim connection As New MySqlConnection(connectionString)
        Dim da As New MySqlDataAdapter(query, connection)
        Dim ds As New DataSet()        Dim myAdapter As New MySqlDataAdapter
        myAdapter = New MySqlDataAdapter(query, connection)
        myAdapter.Fill(ds, "status")
        Dim dt As DataTable = New DataTable() 'DataTable Initializes a new instance of the DataTable class with no arguments.
        da.Fill(dt)        Dim checkbox As CheckBox = CType(sender, CheckBox)
        Dim row As GridViewRow = CType(checkbox.NamingContainer, GridViewRow)
        Dim i As Integer        For i = 0 To dt.Rows.Count - 1 Step i + 1
            If (dt.Rows(i)("WONumber").ToString = row.Cells(1).Text.ToString()) Then
                indx = i            End If        Next
        txtWON.Text = dt.Rows(indx)("WONumber").ToString()
        txtPartNumber.Text = dt.Rows(indx)("PartNumber").ToString()
        txtRev.Text = dt.Rows(indx)("Rev").ToString()
        txtCust.Text = dt.Rows(indx)("Customer").ToString()
        DDCR.Text = dt.Rows(indx)("CRep").ToString()
        DDAE.Text = dt.Rows(indx)("AEng").ToString()
        txtOQty.Text = dt.Rows(indx)("OrderQty").ToString()
        DDPR.Text = dt.Rows(indx)("PReceived").ToString
        txtFDD.Text = dt.Rows(indx)("FabDue").ToString()
        txtFCD.Text = dt.Rows(indx)("FabComp").ToString()
        txtADD.Text = dt.Rows(indx)("AssyDue").ToString
        txtACD.Text = dt.Rows(indx)("AssyComp").ToString()
        txtTDD.Text = dt.Rows(indx)("TestDue").ToString()
        txtTCD.Text = dt.Rows(indx)("TestComp").ToString()
        txtDes.Text = dt.Rows(indx)("Notes").ToString()
        txtShipQty.Text = dt.Rows(indx)("ShippedQty").ToString()
        DDStatus.Text = dt.Rows(indx)("Status").ToString()    End Sub

Hi, Give your chkSelect_CheckedChanged event handler as below.

 

1. First you clear your textboxes.

2. In the loop, you uncheck previous checkboxes

3. Finally if you have checked any checkbox, then that line will have its value filled in the textboxes.

Just make sure that you are using the same query for filling the datatable and also for binding the gridview.

Hope this helps.

 

 

Protected Sub chkSelect_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        txtWON.Text = ""        txtPartNumber.Text = ""        txtRev.Text = ""
        txtCust.Text = ""        DDCR.Text = ""        DDAE.Text = ""
        txtOQty.Text = ""        DDPR.Text = ""        txtFDD.Text = ""
        txtFCD.Text = ""        txtADD.Text = ""        txtACD.Text = ""
        txtTDD.Text = ""        txtTCD.Text = ""        txtDes.Text = ""
        txtShipQty.Text = ""        DDStatus.Text = ""
        Dim indx As Integer
        Dim connectionString As String = "Database=pjt;" & "Data Source=localhost;" & "User Id=root;Password=prasad123"
        Dim query As String = "Select WONumber,PartNumber,Rev,customer,CRep,AEng,Orderqty,PReceived,FabDue,FabComp,AssyDue,AssyComp,TestDue,TestComp,Notes,Shippedqty,status from status"
        'Dim query As String = "Select partnumber from status"
        Dim connection As New MySqlConnection(connectionString)
        Dim da As New MySqlDataAdapter(query, connection)
        Dim ds As New DataSet()        Dim myAdapter As New MySqlDataAdapter
        myAdapter = New MySqlDataAdapter(query, connection)
        myAdapter.Fill(ds, "status")
        Dim dt As DataTable = New DataTable() 'DataTable Initializes a new instance of the DataTable class with no arguments.
        da.Fill(dt)        Dim checkbox As CheckBox = CType(sender, CheckBox)
        Dim row As GridViewRow = CType(checkbox.NamingContainer, GridViewRow)
        Dim i As Integer        For i = 0 To dt.Rows.Count - 1 Step i + 1
            If (dt.Rows(i)("WONumber").ToString = row.Cells(1).Text.ToString()) Then
                indx = i            Else
                Dim loopCheckBox As CheckBox = CType(GVStatus.Rows(i).Cells(0).Controls(1), CheckBox)
                loopCheckBox.Checked = False            End If        Next
        If (checkbox.Checked) Then
            txtWON.Text = dt.Rows(indx)("WONumber").ToString()
            txtPartNumber.Text = dt.Rows(indx)("PartNumber").ToString()
            txtRev.Text = dt.Rows(indx)("Rev").ToString()
            txtCust.Text = dt.Rows(indx)("Customer").ToString()
            DDCR.Text = dt.Rows(indx)("CRep").ToString()
            DDAE.Text = dt.Rows(indx)("AEng").ToString()
            txtOQty.Text = dt.Rows(indx)("OrderQty").ToString()
            DDPR.Text = dt.Rows(indx)("PReceived").ToString
            txtFDD.Text = dt.Rows(indx)("FabDue").ToString()
            txtFCD.Text = dt.Rows(indx)("FabComp").ToString()
            txtADD.Text = dt.Rows(indx)("AssyDue").ToString
            txtACD.Text = dt.Rows(indx)("AssyComp").ToString()
            txtTDD.Text = dt.Rows(indx)("TestDue").ToString()
            txtTCD.Text = dt.Rows(indx)("TestComp").ToString()
            txtDes.Text = dt.Rows(indx)("Notes").ToString()
            txtShipQty.Text = dt.Rows(indx)("ShippedQty").ToString()
            DDStatus.Text = dt.Rows(indx)("Status").ToString()        End If
    End Sub

 

Wow pretty precise solution Lateef,Thank you so much,Have a Great day.

thoughts on "[RESOLVED] Avoid loding data when user unselect"

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>