Problem solve Get help with specific problems with your technologies, process and projects.

Make an editable datagrid

This tip explains how to easily make a datagrid editable with paging.

Please let other users know how useful this tip is by rating it at the bottom of the page. Do you have a tip or code of your own you'd like to share? Submit it here.


This tip explains how to easily make a datagrid editable with paging. In the properties of the datagrid, we have EnableViewState=true and AllowPaging=true.

In the property pages of the datagrid, in Columns, we choose Button Column and add a new one that we name Update. On its click, we take the current row of data and go to another page where we get the record data and can work on it.


private void Page_Load(object sender, System.EventArgs e)
{
 this.dataSet11.Clear();
 this.sqlDataAdapter1.Fill(this.dataSet11);
 IncidentsDataGrid.DataBind();
}

private void IncidentDataGrid_ItemCommand(object source, 
System.Web.UI.WebControls.DataGridCommandEventArgs e)
  {
   if (e.CommandName=="Upd")
   {
 int curridx = Convert.ToInt16(e.Item.Cells[1].Text.ToString());
    Response.Redirect(".\\InsertUpdateForm.aspx?
insupd=upd&curridx=" + curridx);
   }
  }

  private void IncidentsDataGrid_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
  {
 this.IncidentsDataGrid.CurrentPageIndex=e.NewPageIndex;
   this.IncidentsDataGrid.DataBind();
  }

Dig Deeper on C# programming language

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

TheServerSide.com

Close