[英]ASP.NET Gridview OnUpdating event not updating decimal value
[英]How to differentiate updating or inserting in GridView OnUpdating Event?
我使用ASP.NET在我的Web應用程序的工作,我進入了一個情況,我需要區分更新和插入在GridView控件更新事件的情況。
protected void GridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//conditional check
if(Update Flage){
//Call Update Function
}
else{
//Call Insert Function
}
}
我在GridView中有一個ItemTemplate和EditItemTemplate ,當單擊Edit Button(位於ItemTemplate上),然后更改為Update Button(位於EditItemTemplate上)時。
我在GridView之外有一個Add Button,單擊后,將新的Row添加到GridView中,並將Button文本更改為ADD ,如下代碼片段:
ds.Tables[0].Rows.InsertAt(ds.Tables[0].NewRow(), 0);
GridViewID.EditIndex = 0;
LinkButton cmdButton = GridView.Rows[0].FindControl("btnUpdate") as LinkButton;
cmdButton.Text = "Add";
我知道有用於行插入的InsertItemTemplate,但是在我的情況下,我是使用GridView之外的Button來添加新的編輯行。
因此,如何區分RowUpdating事件的編輯或插入? 任何建議的技巧來實現這一目標? 也許像添加一個HiddenField作為標志之類的東西。
在此先感謝您。
您可以根據該命令名稱值識別事件
例如。
protected void GridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string arg = e.CommandName.ToString();
if(arg="Edit")
{
}
else if(arg=="Update")
{
}
標記
<asp:LinkButton ID="lnkEdit" Text="Customize" CommandName="edit" CommandArgument='edit' runat="server">
</asp:LinkButton>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.