作者:mobiledu2502913173 | 来源:互联网 | 2023-09-23 12:55
前端:1、给GridView中添加一模板列,将数据(ID)直接绑定到按钮的CommandArgument中,在RowCommand事件中的e.CommandArguemnt就能读出绑定的数据了
前端:
1、 给GridView中添加一模板列,将数据(ID)直接绑定到按钮的CommandArgument中,在RowCommand事件中的e.CommandArguemnt就能读出绑定的数据了。这样只能绑定一个数据。 要实现多数据绑定,通过CommandArgument=<’Container.DataItemIndex’>绑定行的索引号。
2、要实现不能重复提交,要使用LinkButton 的Enabled属性使用后台方法进行格式化,返回True或者False。
后台:通过CommandName参数选中触发的按钮,通过CommandArgument获得绑定的行数据。如果绑定的数据是GUID数据,要使用 new Guid(e.CommandArgument.ToString())来转换。
protected void gv_ReviewIndex_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Submmit")
{
using (SqlConnection cOnn= new SqlConnection(sConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("update tbReview set ReviewSubmmitState ='已提交' where ReviewMajorID='" + new Guid(e.CommandArgument.ToString()) + "' and ReviewUserID='" + Session["UserID"].ToString() + "'", conn))
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", string.Format("", cmd.ExecuteNonQuery()));
}
}
}
SetBind();
}
实现提交后按钮不能再次提交,后台方法格式化。
public bool FormatBool(string strSubmmitState)
{
if (strSubmmitState.Trim() == "已提交?")
return false;
else
return true;
}