Showing posts with label Events in GridView. Show all posts
Showing posts with label Events in GridView. Show all posts

Feb 11, 2010

Events in GridView control of ASP.NET

For Edit
void myGridView_RowEditing(object sender, GridViewEditEventArgs e)
{
myGridView.EditIndex = e.NewEditIndex;
BindData();
}

//

For Cancel
void myGridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
myGridView.EditIndex = -1;
BindData();
}

For Update
void myGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = myGridView.Rows[e.RowIndex];
if (row != null)
{
TextBox t = row.FindControl("TextBox1") as TextBox;
if (t != null)
{
Response.Write("The Text Entered is" + t.Text);
}
}

For Select
void myGridView_SelectedIndexChanged(object sender, EventArgs e)
{
// This will contain the selectedValue of the row
string selectedCategory = myGridView.SelectedRow.Cells[1].Text;
}

For paging
void myGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
myGridView.PageIndex = e.NewPageIndex;
BindData();
}

// In Datagrid
OnPageIndexChanged ="PageData"
protected void PageData(Object source, DataGridPageChangedEventArgs e )
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
Binddata();
}