using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
public partial class admin_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
}
protected void btnSokDB_Click(object sender, EventArgs e)
{
//Response.Redirect("Sok.aspx?btnSok_Maskiner=1".ToString());
}
}
Can you please make sure that you are allowing auto post backs ( in markup for your gridview please add autopostback="true" ) for the first gridview ? And also please try using
GridView1.databind();
with the appropriate use of
IsPostback() function
returns true/false
if necessary.
Kindly mark this post as an answer if it does the trick.
nettmester
Member
105 Points
99 Posts
Refresh GridView
Nov 19, 2012 07:02 PM|LINK
I cant seem to find an answear for this problem.
I have two GridViews in a page.
One of them displays all the records from a table, ono of them displays search (from textfield and asp:button).
When i search for a item and deletes it, then the first GridView doesnt refresh before i press the search button again.
So how can i refresh both GridViews at same time?
Nakor
Member
336 Points
60 Posts
Re: Refresh GridView
Nov 19, 2012 07:46 PM|LINK
in the OnRowDeleted event of the GridView that does the deleting you'll need to call the databind method of the other GridView
oned_gk
All-Star
36084 Points
7366 Posts
Re: Refresh GridView
Nov 19, 2012 09:54 PM|LINK
Suwandi - Non Graduate Programmer
sarathi125
Star
13599 Points
2691 Posts
Re: Refresh GridView
Nov 20, 2012 12:15 AM|LINK
Hi,
Try like this,
protected void gv1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int instructionId = (int)gv1.DataKeys[e.RowIndex].Value; /// my delete logic CTX.SubmitChanges(); GridView2.DataBind(); }Or if you are using ajax then put the two grids in a sinle update panel and use the updatepanel refresh.
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
nettmester
Member
105 Points
99 Posts
Re: Refresh GridView
Nov 25, 2012 06:23 PM|LINK
That didnt do it. Perhaps i did wrong in my code.
See code below. If you could fill inn whats nessesarry id be glad.
<%@ Page Language="C#" MasterPageFile="~/Admin/admin.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="admin_Default" Title="Untitled Page" %> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <div id="wrap"> <h3 style="margin-left:5px">Registrer bok i databasen</h3> <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DefaultMode="Insert" DataKeyNames="ID"> <InsertItemTemplate> <asp:Panel ID="Panel1" runat="server" DefaultButton="InsertButton"> <table class="Fv"> <tr><td>Ip nr:</td> <td><asp:TextBox ID="IpnrTextBox" runat="server" Text='<%# Bind("Ipnr") %>' /> </td></tr> <tr><td>Dewey: <td><asp:TextBox ID="DeweyTextBox" runat="server" Text='<%# Bind("Dewey") %>' /> </td></tr> <tr><td>Forfatter: <td><asp:TextBox ID="ForfatterTextBox" runat="server" Text='<%# Bind("Forfatter") %>' /> </td></tr> <tr><td>Tittel: <td><asp:TextBox ID="TittelTextBox" runat="server" Text='<%# Bind("Tittel") %>' /> </td></tr> <tr><td>Utg. sted: <td><asp:TextBox ID="Utg_stedTextBox" runat="server" Text='<%# Bind("Utg_sted") %>' /> </td></tr> <tr><td>Plassering: <td><asp:TextBox ID="PlasseringTextBox" runat="server" Text='<%# Bind("Plassering") %>' /> </td></tr> <tr><td>Kommentar: <td><asp:TextBox ID="KommentarTextBox" runat="server" Text='<%# Bind("Kommentar") %>' /> </td></tr> <tr><td>Ank. nr: <td><asp:TextBox ID="Ank_nrTextBox" runat="server" Text='<%# Bind("Ank_nr") %>' /> </td></tr> <tr><td>ISBN/ISSBN: <td><asp:TextBox ID="ISBN_ISSBNTextBox" runat="server" Text='<%# Bind("ISBN_ISSBN") %>' /> </td></tr> <tr><td>Forlag: <td><asp:TextBox ID="ForlagTextBox" runat="server" Text='<%# Bind("Forlag") %>' /> </td></tr> <tr><td>Utgitt år: <td><asp:TextBox ID="Utgitt_aarTextBox" runat="server" Text='<%# Bind("Utgitt_aar") %>' /> </td></tr> </table> <br /> <asp:LinkButton ID="InsertCancelButton" CssClass="btnFvSettinn" runat="server" CausesValidation="False" CommandName="Cancel" Text="Avbryt" /> <asp:LinkButton ID="InsertButton" CssClass="btnFvAvbryt" runat="server" CausesValidation="True" CommandName="Insert" Text="Sett inn" /> </asp:Panel> </InsertItemTemplate> </asp:FormView> <br /><br /> <h3 style="margin-left:5px">Registrerte oppføringer (Siste oppføring øverst)</h3> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" Font-Names="Verdana" Font-Size="11px" Width="100%" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" PagerStyle-VerticalAlign="Top" HorizontalAlign="Justify" GridLines="None" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt" > <Columns> <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="LinkBtnDelete" runat="server" OnClientClick="return confirm('OK to Delete?');" CommandName="Delete">Delete </asp:LinkButton> </ItemTemplate> </asp:TemplateField> <asp:CommandField ShowDeleteButton="False" ShowEditButton="True" /> <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" /> <asp:BoundField DataField="Dewey" HeaderText="Dewey" SortExpression="Dewey" /> <asp:BoundField DataField="Ipnr" HeaderText="Ip nr" SortExpression="Ipnr" /> <asp:BoundField DataField="Forfatter" HeaderText="Forfatter" SortExpression="Forfatter" /> <asp:BoundField DataField="Tittel" HeaderText="Tittel" SortExpression="Tittel" /> <asp:BoundField DataField="Utg_sted" HeaderText="Utg. sted" SortExpression="Utg_sted" /> <asp:BoundField DataField="Plassering" HeaderText="Plassering" SortExpression="Plassering" /> <asp:BoundField DataField="Kommentar" HeaderText="Kommentar" SortExpression="Kommentar" /> <asp:BoundField DataField="Ank_nr" HeaderText="Ank. nr" SortExpression="Ank_nr" /> <asp:BoundField DataField="ISBN_ISSBN" HeaderText="ISBN/ISSBN" SortExpression="ISBN_ISSBN" /> <asp:BoundField DataField="Forlag" HeaderText="Forlag" SortExpression="Forlag" /> <asp:BoundField DataField="Utgitt_aar" HeaderText="Utgitt år" SortExpression="Utgitt_aar" /> </Columns> <FooterStyle ForeColor="#CCCCCC" /> <PagerStyle VerticalAlign="Top" /> <AlternatingRowStyle CssClass="alt"></AlternatingRowStyle> </asp:GridView> <br /> <asp:Panel ID="Panel1" runat="server" defaultbutton="btnSokDB"> <h3 style="margin-left:5px">Søk i oppføringer</h3> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:Button ID="btnSokDB" runat="server" Text="Søk" Height="22px" OnClick="btnSokDB_Click" /> <br /> <asp:GridView ID="GridView2" runat="server" AllowPaging="True" AllowSorting="True" PageSize="100" Font-Names="Verdana" Font-Size="11px" Width="100%" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource2" PagerStyle-VerticalAlign="Top" HorizontalAlign="Justify" GridLines="None" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt" > <Columns> <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="LinkBtnDelete" runat="server" OnClientClick="return confirm('OK to Delete?');" CommandName="Delete">Delete </asp:LinkButton> </ItemTemplate> </asp:TemplateField> <asp:CommandField ShowDeleteButton="False" ShowEditButton="True" /> <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" /> <asp:BoundField DataField="Dewey" HeaderText="Dewey" SortExpression="Dewey" /> <asp:BoundField DataField="Ipnr" HeaderText="Ip nr" SortExpression="Ipnr" /> <asp:BoundField DataField="Forfatter" HeaderText="Forfatter" SortExpression="Forfatter" /> <asp:BoundField DataField="Tittel" HeaderText="Tittel" SortExpression="Tittel" /> <asp:BoundField DataField="Utg_sted" HeaderText="Utg. sted" SortExpression="Utg_sted" /> <asp:BoundField DataField="Plassering" HeaderText="Plassering" SortExpression="Plassering" /> <asp:BoundField DataField="Kommentar" HeaderText="Kommentar" SortExpression="Kommentar" /> <asp:BoundField DataField="Ank_nr" HeaderText="Ank. nr" SortExpression="Ank_nr" /> <asp:BoundField DataField="ISBN_ISSBN" HeaderText="ISBN/ISSBN" SortExpression="ISBN_ISSBN" /> <asp:BoundField DataField="Forlag" HeaderText="Forlag" SortExpression="Forlag" /> <asp:BoundField DataField="Utgitt_aar" HeaderText="Utgitt år" SortExpression="Utgitt_aar" /> </Columns> <FooterStyle ForeColor="#CCCCCC" /> <PagerStyle VerticalAlign="Top" /> <AlternatingRowStyle CssClass="alt"></AlternatingRowStyle> </asp:GridView> </asp:Panel> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:db143323ConnectionString %>" SelectCommand="SELECT [ID], [Dewey], [Ipnr], [Forfatter], [Tittel], [Utg_sted], [Plassering], [Kommentar], [Ank_nr], [ISBN_ISSBN], [Forlag], [Utgitt_aar] FROM [boeker2] order by id desc" DeleteCommand="DELETE FROM [boeker2] WHERE [ID] = @ID" InsertCommand="INSERT INTO [boeker2] ([Dewey], [Ipnr], [Forfatter], [Tittel], [Utg_sted], [Plassering], [Kommentar], [Ank_nr], [ISBN_ISSBN], [Forlag], [Utgitt_aar]) VALUES (@Dewey, @Ipnr, @Forfatter, @Tittel, @Utg_sted, @Plassering, @Kommentar, @Ank_nr, @ISBN_ISSBN, @Forlag, @Utgitt_aar)" UpdateCommand="UPDATE [boeker2] SET [Dewey] = @Dewey, [Ipnr] = @Ipnr, [Forfatter] = @Forfatter, [Tittel] = @Tittel, [Utg_sted] = @Utg_sted, [Plassering] = @Plassering, [Kommentar] = @Kommentar, [Ank_nr] = @Ank_nr, [ISBN_ISSBN] = @ISBN_ISSBN, [Forlag] = @Forlag, [Utgitt_aar] = @Utgitt_aar WHERE [ID] = @ID"> <DeleteParameters> <asp:Parameter Name="ID" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="Dewey" Type="String" /> <asp:Parameter Name="Ipnr" Type="String" /> <asp:Parameter Name="Forfatter" Type="String" /> <asp:Parameter Name="Tittel" Type="String" /> <asp:Parameter Name="Utg_sted" Type="String" /> <asp:Parameter Name="Plassering" Type="String" /> <asp:Parameter Name="Kommentar" Type="String" /> <asp:Parameter Name="Ank_nr" Type="String" /> <asp:Parameter Name="ISBN_ISSBN" Type="String" /> <asp:Parameter Name="Forlag" Type="String" /> <asp:Parameter Name="Utgitt_aar" Type="String" /> <asp:Parameter Name="ID" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="Ipnr" Type="String" /> <asp:Parameter Name="Dewey" Type="String" /> <asp:Parameter Name="Forfatter" Type="String" /> <asp:Parameter Name="Tittel" Type="String" /> <asp:Parameter Name="Utg_sted" Type="String" /> <asp:Parameter Name="Utgitt_aar" Type="String" /> <asp:Parameter Name="Forlag" Type="String" /> <asp:Parameter Name="ISBN_ISSBN" Type="String" /> <asp:Parameter Name="Ank_nr" Type="String" /> <asp:Parameter Name="Kommentar" Type="String" /> <asp:Parameter Name="Plassering" Type="String" /> </InsertParameters> </asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:db143323ConnectionString %>" SelectCommand="select * from boeker2 where Forfatter like '%' + @sokeord+'%' or Tittel like '%' + @sokeord+'%' order by [Forfatter], [Tittel]" DeleteCommand="DELETE FROM [boeker2] WHERE [ID] = @ID" InsertCommand="INSERT INTO [boeker2] ([Dewey], [Ipnr], [Forfatter], [Tittel], [Utg_sted], [Plassering], [Kommentar], [Ank_nr], [ISBN_ISSBN], [Forlag], [Utgitt_aar]) VALUES (@Dewey, @Ipnr, @Forfatter, @Tittel, @Utg_sted, @Plassering, @Kommentar, @Ank_nr, @ISBN_ISSBN, @Forlag, @Utgitt_aar)" UpdateCommand="UPDATE [boeker2] SET [Dewey] = @Dewey, [Ipnr] = @Ipnr, [Forfatter] = @Forfatter, [Tittel] = @Tittel, [Utg_sted] = @Utg_sted, [Plassering] = @Plassering, [Kommentar] = @Kommentar, [Ank_nr] = @Ank_nr, [ISBN_ISSBN] = @ISBN_ISSBN, [Forlag] = @Forlag, [Utgitt_aar] = @Utgitt_aar WHERE [ID] = @ID"> <SelectParameters> <asp:ControlParameter ControlID="TextBox1" Name="sokeord" PropertyName="Text" /> </SelectParameters> <DeleteParameters> <asp:Parameter Name="ID" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="Dewey" Type="String" /> <asp:Parameter Name="Ipnr" Type="String" /> <asp:Parameter Name="Forfatter" Type="String" /> <asp:Parameter Name="Tittel" Type="String" /> <asp:Parameter Name="Utg_sted" Type="String" /> <asp:Parameter Name="Plassering" Type="String" /> <asp:Parameter Name="Kommentar" Type="String" /> <asp:Parameter Name="Ank_nr" Type="String" /> <asp:Parameter Name="ISBN_ISSBN" Type="String" /> <asp:Parameter Name="Forlag" Type="String" /> <asp:Parameter Name="Utgitt_aar" Type="String" /> <asp:Parameter Name="ID" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="Ipnr" Type="String" /> <asp:Parameter Name="Dewey" Type="String" /> <asp:Parameter Name="Forfatter" Type="String" /> <asp:Parameter Name="Tittel" Type="String" /> <asp:Parameter Name="Utg_sted" Type="String" /> <asp:Parameter Name="Utgitt_aar" Type="String" /> <asp:Parameter Name="Forlag" Type="String" /> <asp:Parameter Name="ISBN_ISSBN" Type="String" /> <asp:Parameter Name="Ank_nr" Type="String" /> <asp:Parameter Name="Kommentar" Type="String" /> <asp:Parameter Name="Plassering" Type="String" /> </InsertParameters> </asp:SqlDataSource> </div> </asp:Content>using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; using System.IO; public partial class admin_Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache); } protected void btnSokDB_Click(object sender, EventArgs e) { //Response.Redirect("Sok.aspx?btnSok_Maskiner=1".ToString()); } }aarsh
Participant
1547 Points
435 Posts
Re: Refresh GridView
Nov 25, 2012 07:43 PM|LINK
Can you please make sure that you are allowing auto post backs ( in markup for your gridview please add autopostback="true" ) for the first gridview ? And also please try using
with the appropriate use of
if necessary.
Kindly mark this post as an answer if it does the trick.