.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

refresh a gridview

Posted By: manju     Posted Date: October 30, 2009    Points:2   Category :C#
in gridview i want to update a record, when i click edit button in gridview, whole page is refreshing.my requirement is when edit a row in grid , only grid has to refresh.not whole page.
am using asp.net with c#....

Responses
Author: Amit Mehra             
Posted Date: October 30, 2009     Points: 5   

HI Manu,

you can use Ajax Update panel ato refresh only gridview.

Place the gridview inside update panel and inside trigger Tag you can to attach the click event for eg

<ajax:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional">                                <ContentTemplate>                                        <asp:GridView ID="GridView" Visible="false" runat="server"  HeaderStyle-Width="200" HeaderStyle-BackColor="#2B6292" HeaderStyle-ForeColor="White"                                         AllowSorting="true" AllowPaging="true" Width="600" AutoGenerateColumns="False" OnRowCreated="GridView_OnRowCreated"                                         DataKeyNames="Id" onsorting="GridView_OnSort">                                                <Columns>                                                        ...                                                </Columns>                                        </asp:GridView>                                </ContentTemplate>                                <Triggers>                                        <ajax:AsyncPostBackTrigger ControlID="CreateButton"/>                                </Triggers>                        </ajax:UpdatePanel>


Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: Syed Shakeer Hussain             
Posted Date: October 30, 2009     Points: 5   

Hi,
In Page Load write below code to avoid page refresh:

conn = new SqlConnection("Data Source=INTHIYAAZ;Initial Catalog=shakeer;uid=sa;pwd=sa;");
if(!IsPostBack )
{
bind();
}

For updating a Gridview write below code:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
Label lbl = (Label)row.FindControl("lblid");
TextBox textname = (TextBox)row.FindControl("textbox1");
TextBox textmarks = (TextBox)row.FindControl("textbox2");

GridView1.EditIndex = -1;
conn.Open();
SqlCommand cmd = new SqlCommand("update emp set marks=" + textmarks.Text + " , name='" + textname.Text + "' where rowid=" + lbl.Text + "", conn);

cmd.ExecuteNonQuery();
conn.Close();
bind();


}


public void bind()
{

conn.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from emp", conn);
DataSet ds = new DataSet();
da.Fill(ds, "emp");
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
conn.Close();
}


For more inforation check the below link
http://www.dotnetspark.com/kb/643-how-to-editupdatedelete-gridview.aspx



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend