【发布时间】:2011-06-13 18:19:39
【问题描述】:
我有一个 Asp.net 的 GridView 控件,并且在模板列中我有插入和更新链接按钮以及取消和编辑。
现在,如果插入或更新按钮被触发并且记录成功保存在数据库中,我想触发显示消息“记录插入/更新成功”的查询。 否则消息应该类似于异常或“记录未保存,请重试”
谁能告诉我应该在哪里以及如何编写代码和脚本寄存器?达到同样的效果?
我的代码示例有点像
protected void grvCategory_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
string footerCategoryName = ((TextBox)grvCategory.FooterRow.FindControl("txtFTCategoryName")).Text;
string txtTransactionTypeId = ((DropDownList)grvCategory.FooterRow.FindControl("ddlFTTransactionTypeName")).SelectedItem.Value;
string footerBasePrice = ((TextBox)grvCategory.FooterRow.FindControl("txtFTPrice")).Text;
try
{
string insertCategory = string.Format(SQLQuery.InsertCategory, footerCategoryName, txtTransactionTypeId, footerBasePrice, HttpContext.Current.User.Identity.Name, HttpContext.Current.User.Identity.Name);
int returnValue = SqlHelper.ExecuteNonQuery(ProjectConfig.ConnectionString, CommandType.Text, insertCategory);
if (returnValue > 0)
{
lblMessage.Text = "Record Inserted Successfully";
grvCategory.FooterRow.Attributes.Add("onclick", "javascript:callme();");
}
}
catch (Exception ex)
{
throw ex;
}
}
}
protected void grvCategory_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Footer)
{
Label lblITTransactionTypeId = (Label)e.Row.Cells[2].FindControl("lblITTransactionTypeId");
Label lblITTransactionTypeName = (Label)e.Row.Cells[2].FindControl("lblITTransactionTypeName");
if (lblITTransactionTypeName != null)
lblITTransactionTypeName.Text = StringEnum.GetStringValue((ProjectEnum.TransactionType)(Enum.Parse(typeof(ProjectEnum.TransactionType), lblITTransactionTypeId.Text.ToString())));
DropDownList ddlETTransactionTypeName = (DropDownList)e.Row.Cells[3].FindControl("ddlETTransactionTypeName");
if (ddlETTransactionTypeName != null)
FillTransactionTypeDropDown(ddlETTransactionTypeName, lblITTransactionTypeId.Text);
DropDownList ddlFTTransactionTypeName = (DropDownList)e.Row.Cells[3].FindControl("ddlFTTransactionTypeName");
if (ddlFTTransactionTypeName != null)
FillTransactionTypeDropDown(ddlFTTransactionTypeName, string.Empty);
}
}
【问题讨论】:
标签: javascript jquery asp.net gridview registration