Click here to Skip to main content
15,907,149 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
Can some one help me please.
I have a Gridview which displays the new data entered from the text box and drop downlist with a add button .But it displays once we refresh or postback the
page.
C#
<asp:GridView 
            ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" 
            CellPadding="4" DataKeyNames="SettingId" DataSourceID="SqlDataSource5" 
            ForeColor="#333333" GridLines="None" Height="55px" Width="753px">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:BoundField DataField="SettingType" HeaderText="SettingType" 
                    SortExpression="SettingType" Visible="False" />
                <asp:BoundField DataField="Auth" HeaderText="Auth" 
                    SortExpression="Auth" Visible="False" />
                <asp:BoundField DataField="Group" HeaderText="Group" 
                    SortExpression="Group" Visible="False" />
                <asp:BoundField DataField="Branches" HeaderText="Branches" 
                    SortExpression="Branches" />
                <asp:BoundField DataField="Category" HeaderText="Category" 
                    SortExpression="Category" />
                <asp:BoundField DataField="Bind" HeaderText="Bind" 
                    SortExpression="Bind" Visible="False" />
                <asp:BoundField DataField="Subject" HeaderText="Subject" 
                    SortExpression="Subject" />
                <asp:BoundField DataField="Year" HeaderText="Year" 
                    SortExpression="Year" />
                <asp:BoundField DataField="Id" HeaderText="Id" 
                    InsertVisible="False" ReadOnly="True" SortExpression="Id" 
                    Visible="False" />
                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <asp:Button ID="Button1" runat="server" CausesValidation="false" onclientclick="return confirm('Are you sure you want to delete this Setting?');"
                            CommandName="Delete" Text="" />
                    </ItemTemplate>
                    <ControlStyle CssClass="btnstyle" Height="30px" Width="30px" />
                </asp:TemplateField>
            </Columns>
            <EditRowStyle BackColor="#2461BF" />
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" 
                HorizontalAlign="Left" />
            <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" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource5" runat="server" 
            ConnectionString="<% %>" 
            DeleteCommand="DELETE FROM Setting WHERE (Id = @Id)" 
            
            SelectCommand="SELECT SettingType, Code, Group, Branch, Category, Binding, Subject, Issues, Year, Id FROM Setting WHERE (SettingType = 'something')">
            <DeleteParameters>
                <asp:Parameter Name="Id" />
            </DeleteParameters>
        </asp:SqlDataSource>



I want the grid to show the data inserted as soon as i hit add without post back or refreshing.
Posted
Updated 17-Apr-13 1:54am
v3
Comments
Dnyaneshwar Kondbale 17-Apr-13 6:04am    
Use Update panel for the same. put grid view in update panel and update mode is conditional.
babli3 17-Apr-13 6:05am    
ok let me try thanks
babli3 17-Apr-13 6:18am    
sorry its not updating still
Dnyaneshwar Kondbale 17-Apr-13 6:20am    
are You adding tigers for update panel.???
babli3 17-Apr-13 6:21am    
no i didnt , i will add now. thanks

1 solution

C#
<asp:scriptmanager id="ScriptManager1" runat="server" xmlns:asp="#unknown">
    </asp:scriptmanager>
<asp:updatepanel xmlns:asp="#unknown">
            ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <contenttemplate>
         
// you will have your grid here

</contenttemplate>
<asp:asyncpostbacktrigger controlid="btnUpload" eventname="Click" />
</asp:updatepanel>



in code behind:

on button click event

SQL
GridView1.DataBind();
   UpdatePanel1.Update();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900