开发者

How can I identify the edited row in GridView?

开发者 https://www.devze.com 2023-04-08 01:19 出处:网络
My client wanted the GridView to display fields inside TextBoxes, and DropDownListBoxes only. He wanted the flexibility开发者_如何学C to update the Record just by clicking on the Update button after a

My client wanted the GridView to display fields inside TextBoxes, and DropDownListBoxes only. He wanted the flexibility开发者_如何学C 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!!


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


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


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)         
{         }     
 }


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消