zoukankan      html  css  js  c++  java
  • 六、初学.NET—GridView每行添加提交按钮,提交后不能再次评审。

    前端:

    1、  给GridView中添加一模板列,将数据(ID)直接绑定到按钮的CommandArgument中,在RowCommand事件中的e.CommandArguemnt就能读出绑定的数据了。这样只能绑定一个数据。 要实现多数据绑定,通过CommandArgument=<’Container.DataItemIndex’>绑定行的索引号。

    2、要实现不能重复提交,要使用LinkButton 的Enabled属性使用后台方法进行格式化,返回True或者False。

    <asp:TemplateField HeaderText="基本操作>

                <ItemTemplate>

                    <asp:LinkButton ID="lbtn_Submmit" runat="server" Text='提交' CommandName="Submmit" CommandArgument='<%#Eval("MajorID")%>' OnClientClick="return confirm('确定提交吗?提交后将不可更改。)"  Enabled='<%# FormatBool(Eval("ReviewSubmmitState").ToString()) %>'></asp:LinkButton> 

               </ItemTemplate>

            </asp:TemplateField>

         

    后台:通过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("<script>alert('{0}条记录提交成功。”);location.href=location.href</script>", cmd.ExecuteNonQuery()));

                    }

                }

            }

            SetBind();

        }

    实现提交后按钮不能再次提交,后台方法格式化。

    public bool FormatBool(string strSubmmitState)

        {

            if (strSubmmitState.Trim() == "已提交?")

                return false;

            else

                return true;

         }

  • 相关阅读:
    js点击重置按钮重置表单
    Flash文件在asp页面无法播放,网页上面的Flash文件在火狐浏览器不播放
    更新域名解析以后,IP在cmd中ping不正确,清理DNS缓存
    简单PHP会话(session)说明
    delphi 事件和属性的绑定
    读书笔记(乡土中国)
    读书笔记(支付战争)
    读书笔记(从0到1)
    读书笔记(创业维艰)
    读书笔记(三体)
  • 原文地址:https://www.cnblogs.com/liuyuanhao/p/3012960.html
Copyright © 2011-2022 走看看