我的客戶希望GridView僅在TextBoxes和DropDownListBoxes內顯示字段。他希望靈活性更改記錄,只需在更改單元格中的值後單擊更新按鈕即可。如何識別GridView中的已編輯行?
他想要以某種不同的顏色編輯GridViewRow,以便他可以單擊該特定行的「更新」按鈕。
如何識別GridView中當前的編輯行?由於沒有編輯按鈕點擊!
我的客戶希望GridView僅在TextBoxes和DropDownListBoxes內顯示字段。他希望靈活性更改記錄,只需在更改單元格中的值後單擊更新按鈕即可。如何識別GridView中的已編輯行?
他想要以某種不同的顏色編輯GridViewRow,以便他可以單擊該特定行的「更新」按鈕。
如何識別GridView中當前的編輯行?由於沒有編輯按鈕點擊!
也許你正在尋找GridView.EditIndex
另外這裏的教程,它看起來像適合您的問題:http://csharpdotnetfreak.blogspot.com/2009/05/gridview-sqldatasource-insert-edit.html
基於GridView的行EditItemIndex你可以找到一個行是否是在編輯模式下與否。瞭解更多信息,請參閱this。
你在說多行編輯嗎?或者所有行都顯示可編輯UI的場景?如果是這種情況,最好的方法是對所有字段使用TemplateFields,並在模板中渲染文本框/其他控件。開箱即用,不支持多行編輯。
或者你可以創建一個像什麼在這裏做了一個自定義的控制:http://blogs.msdn.com/b/mattdotson/archive/2005/11/09/real-world-gridview-bulk-editing.aspx
如果你說的簡單的編輯,選擇AutoGenerateUpdateButton =「true」會添加更新按鈕,或手動添加一個CommandField,並設置其要更新的命令名稱。
HTH。
您可以使用此代碼選擇行,並以不同的顏色顯示行。 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)
{ }
}