user3368990
user3368990

Reputation: 17

gridview doesn't show update data after click event

i have filled gridview with Store procedure which needs registrationNo parameter so TEXTBOX is control parameter, and that store procedure is on server's database which receives new records from tablet device. It shows new records when i click SEARCH button after entering data in textbox but problem is that if new data is received from tablet and i hit search button then it doesn't show new data, i have to go back to home page then this page and again entering data and clicking search button, then it displays why ?

CODE:

<form id="form1" runat="server">
    <div>
        <asp:Button ID="btnHome" runat="server" Text="Home" CssClass="button" Width="7%" OnClick="btnHome_Click" />
    </div>
    <br />
    <div>
       <asp:Panel ID="pnlInput" runat="server" DefaultButton="btnSearch">
        <asp:TextBox ID="txtboxVehicleNo" runat="server"></asp:TextBox> &nbsp
        <asp:Button ID="btnSearch" Text="Search" Width="9%" CssClass="button" runat="server" OnClick="btnSearch_Click1" />
       </asp:Panel>
    </div>
    <br />
    <br />
    <div>
        <asp:GridView ID="gvVehicleLedger" ShowHeaderWhenEmpty="True" runat="server" CellPadding="7" DataSourceID="SqlDataSourceETTVehicleLed" ForeColor="#333333" GridLines="None" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="Vehicle No" Width="100%" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:BoundField DataField="Vehicle No" HeaderText="Vehicle No" ReadOnly="True" SortExpression="Vehicle No" >
                <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                <ItemStyle HorizontalAlign="Left" />
                </asp:BoundField>
                <asp:BoundField DataField="Transaction Date" HeaderText="Transaction Date" SortExpression="Transaction Date">
                <HeaderStyle HorizontalAlign="Left" />
                <ItemStyle HorizontalAlign="Left" Wrap="False" />
                </asp:BoundField>
                <asp:BoundField DataField="Engine Capacity" HeaderText="Engine Capacity" SortExpression="Engine Capacity" >
                <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                <ItemStyle HorizontalAlign="Left" Wrap="False" />
                </asp:BoundField>
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" >
                <HeaderStyle HorizontalAlign="Left" />
                <ItemStyle HorizontalAlign="Left" />
                </asp:BoundField>
                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" >
                <HeaderStyle HorizontalAlign="Left" />
                <ItemStyle HorizontalAlign="Left" />
                </asp:BoundField>
                <asp:BoundField DataField="No Of Months" HeaderText="No Of Months" SortExpression="No Of Months" >
                <HeaderStyle HorizontalAlign="Center" Wrap="False" />
                <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" >
                <HeaderStyle HorizontalAlign="Right" />
                <ItemStyle HorizontalAlign="Right" />
                </asp:BoundField>
            </Columns>
            <EditRowStyle BackColor="#2461BF" />
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#EFF3FB" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#F5F7FB" />
            <SortedAscendingHeaderStyle BackColor="#6D95E1" />
            <SortedDescendingCellStyle BackColor="#E9EBEF" />
            <SortedDescendingHeaderStyle BackColor="#4870BE" />
            <emptydatarowstyle backcolor="#eff3fb"
              forecolor="Red"/>
            <EmptyDataTemplate>
              No Records Found 
            </EmptyDataTemplate> 
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSourceETTVehicleLed" runat="server" ConnectionString="<%$ ConnectionStrings:ETTConnectionStr %>" SelectCommand="Vehicleledger" SelectCommandType="StoredProcedure">
            <SelectParameters>
                <asp:ControlParameter ControlID="txtboxVehicleNo" Name="RegistrationNo" PropertyName="Text" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
    </div>

    </form>

.cs code:

if(!IsPostBack)
        {
            gvVehicleLedger.Visible = false;
        }

protected void btnSearch_Click1(object sender, EventArgs e)
    {
        gvVehicleLedger.Visible = true;
    }

Upvotes: 0

Views: 1218

Answers (2)

Akki
Akki

Reputation: 121

after searching data you should set grid's data source which is newly data to from search

example

private void serach_click()
{
    // your code to retrieve your data

    gridview.datasource = your data source;
    gridview.databind();
}

Upvotes: 1

Mochi
Mochi

Reputation: 171

looks like you don't refresh your data for the gridView on searchClick. I think you should use smthng like gvVehicleLedger.databind(). (there's a blog about this topic here)

Upvotes: 0

Related Questions