Ashok kumar
Ashok kumar

Reputation: 1611

How can I identify the edited row in GridView?

My client wanted the GridView to display fields inside TextBoxes, and DropDownListBoxes only. He wanted the flexibility to update the Record just by clicking on the Update button after altering the values in the cell.

He wanted the current editing GridViewRow in some different color so that he can click on "Update" button for that particular row.

How can I identify the current editing row in the GridView? Since there is no edit button to click on!!

Upvotes: 1

Views: 466

Answers (4)

Jay
Jay

Reputation: 1309

you can select the Row by using this code,And show the Row with different color. u can highlight,

protected override void Render(System.Web.UI.HtmlTextWriter writer)   
  {         
AddRowSelectToGridView(gridView);        
  base.Render(writer);   
  }      
private void AddRowSelectToGridView(GridView gv)   
  {         
try        
 {            
 foreach (GridViewRow row in gv.Rows)            
 {             
row.Attributes["onmouseover"] = "this.style.cursor='hand';
this.style.textDecoration='underline';";                
row.Attributes["onmouseout"] = "this.style.textDecoration='none';";                 
row.Attributes.Add("onclick",Page.ClientScript.GetPostBackEventReference(gv,"Select$"+row.RowIndex.ToString(), true));           
  }         
}         
catch (Exception ex)         
{         }     
 }

Upvotes: 1

Brian Mains
Brian Mains

Reputation: 50728

Are you talking a multi-line edit? Or a scenario where all rows show their editable UI? The best way, if this is the case, is to use TemplateFields for all fields, and render the textboxes/other controls in the template. Out of the box, multi-row editing is not supported.

Or you can create a custom control like what was done here: http://blogs.msdn.com/b/mattdotson/archive/2005/11/09/real-world-gridview-bulk-editing.aspx

If you are talking simply editing, selecting the AutoGenerateUpdateButton="true" will add an update button, or manually add a commandfield and set its CommandName to update.

HTH.

Upvotes: 0

Based on Gridview rows EditItemIndex you can find whether a row is in Edit mode or not. Refer to this to know more.

Upvotes: 1

Samich
Samich

Reputation: 30095

Probably you are looking for GridView.EditIndex

Also here is tutorial which looks like fit your problem: http://csharpdotnetfreak.blogspot.com/2009/05/gridview-sqldatasource-insert-edit.html

Upvotes: 1

Related Questions