locked
Gridview row addition refresh RRS feed

  • Question

  • User-1426568392 posted

    Hello All,

    I am searching a vin number from database table and adding one by one to gridview (Wheni am entering or selecting in dropdown in the search row), when i add the new row the old row refreshes and entered text become blank.

    In othere word the page refresh after adding each row and i want to avoid this.

    Hope i explain well and need more i will tell.

    below my code 

    Thanks



    <asp:GridView ID="GVResrv" runat="server" Width="100%" AutoGenerateColumns="false" TabIndex="1" Font-Names="Times New Roman" Font-Size="Smaller" HeaderStyle-HorizontalAlign="Center" > <Columns > <asp:CommandField ShowSelectButton="true" HeaderText="Details" SelectText="Details" /> <asp:TemplateField HeaderText="Add"> <ItemTemplate> <asp:CheckBox ID="chkGvResrvRow" runat="server" Checked="true" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Vin" HeaderText="VinNumber" /> <asp:BoundField DataField="Model No_" HeaderText="Model No" /> <asp:BoundField DataField="Model Year" HeaderText="Model Year" /> <asp:BoundField DataField="Model Code" HeaderText="Model Code" /> <asp:BoundField DataField="Color" HeaderText="Color" /> <asp:BoundField DataField="Location" HeaderText="Location" /> <asp:BoundField DataField="Status" HeaderText="Status" /> <asp:TemplateField HeaderText="Sales Person"> <ItemTemplate> <asp:TextBox ID="txtSalesPersonName" runat="server" Text='<%# Eval("Sales_Person_Name") %>' /> </ItemTemplate> <ItemTemplate> <asp:DropDownList ID="ddlSalesPerson" runat="server" CssClass="ddldp" DataSourceID="SqlDataSource2" DataTextField="SalesPersonName" DataValueField="SalesPersonName" AppendDataBoundItems="true"> <asp:ListItem Text="Select" Value="0" /> </asp:DropDownList> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:VehicleConnectionString1 %>" SelectCommand="Select SPNID,SalesPersonName from R_ResrvSalesPerson order by SalesPersonName"> </asp:SqlDataSource> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Plate" Visible="false"> <ItemTemplate> <asp:TextBox ID="txtPlate" runat="server" Text='<%# Eval("Plate") %>' Width="70" Visible="false" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Stock Type"> <ItemTemplate> <asp:TextBox ID="txtStockType" runat="server" Text='<%# Eval("Stock_Type") %>' /> </ItemTemplate> <ItemTemplate> <asp:DropDownList ID="ddlStockType" runat="server" DataSourceID="SqlDataSource1" DataTextField="StockType" DataValueField="StockType" AppendDataBoundItems="true"> <asp:ListItem Text="Fleet" Value="Fleet" /> </asp:DropDownList> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:VehicleConnectionString1 %>" SelectCommand="Select StockId,StockType from R_StockType"> </asp:SqlDataSource> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Remarks"> <ItemTemplate> <asp:TextBox ID="txtRemarks" runat="server" Text='<%# Eval("Resrv_Remarks") %>' /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Check_Remarks" HeaderText="P Remarks" /> </Columns> </asp:GridView>

     Dim dtt, dtt1 As New DataTable  
    
     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If IsPostBack = False Then
            Else
                dtt1 = CType(Session("Code"), DataTable)
            End If
    
        End Sub
    
    Protected Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
     Sql = "SELECT  [OCN #], Vin, [Model Year], [Model No_],[Model Code], [Stock No_], [Location],Status,DropOffDate as 'ExpDate',SName FROM R_ResrvStock where Vin='" & txtSearchVinNo.Text & "' order by [Status],[Purchase Date],Vin "
       
     Session("Code") = dtt
            If dtt1 Is Nothing Then
            Else
                dtt.Merge(dtt1)
            End If
    
            '' For to find duplicate and insert
            aD.Fill(dtGvSrch)
            'GVResrv.DataSource = dtGvSrch
            ''
            GVResrv.DataSource = dtt
            GVResrv.DataBind()
    End Sub
    

    Monday, November 14, 2016 11:42 AM

All replies

  • User-1838255255 posted

    Hi sth_syed,

    According to your description, as far as I know, 

    1. you can write value in textbox control, then click button send value to server.

    2.server judge value, if success, insert into database, then return one success single value! 

    3.judge this value, if ok, use GridView append() value to GridView. this will not refresh before rows data.

    For more detail, you can refer this sample:

    Dynamically Add Rows to GridView using jQuery on Button Click in ASP.Net:

    http://www.aspsnippets.com/Articles/Dynamically-Add-Rows-to-GridView-using-jQuery-on-Button-Click-in-ASPNet.aspx 

    Best Regards,

    Eric Du

    Tuesday, November 15, 2016 8:25 AM