Friday, September 30, 2011
SetFocus to TextBox in GridView control
Set Focus to TextBox in GridView when click on Edit
Some time we have requirement to set focus in gridview,so here i am describing to how to this.
Drag and drop a gridview and bind it according to below code.
protected void GridViewBind()
{
try
{
Ds = obBLLclass.GetData();
if (Ds.Tables[0].Rows.Count > 0)
{
gridview.DataSource = Ds;
gridview.DataBind();
}
}
catch (Exception ex)
{
Message.Text = ex.Message;
}
}
protected void gridview_RowEditing(object sender, GridViewEditEventArgs e)
{
gridview.EditIndex = e.NewEditIndex;
GridViewBind();
gridview.Rows[e.NewEditIndex].FindControl("txtname").Focus();
}
protected void gridview_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gridview.PageIndex = e.NewPageIndex;
GridViewBind();
}