none
FormView中Item Template和EditItem Template 之间的参数是如何传递的? RRS feed

  • 问题

  •     FormView中有Item Template和EditItem Template 两个模板,

        我想比较

    Item Template 中   控件ContractNumberLabel  和

    EditItem Template 控件ContractNumberTextBox

    的值当我点击 ItemTemplate界面中的编辑功能键时,却出现了如下图所示错误,该如何解决呢?

    ---------------------代码-------------------------

     protected void CustomValidator_ContractNumber_ServerValidate(object source, ServerValidateEventArgs args)
        {
            string strconn = "Data Source=.;Initial Catalog=长铁物业公司资产数据库;Integrated Security=True";
            SqlConnection cn = new SqlConnection(strconn);
            cn.Open();
            string strConditionLabel = ((Label)this.FormView1.FindControl("ContractNumberLabel")).Text;
            string strConditionText = ((TextBox)this.FormView1.FindControl("ContractNumberTextBox")).Text;
            string strSearch = "select  (case when COUNT(ContractNumber)=0 then 1  when COUNT(ContractNumber)>=1 and COUNT (CID)=1 then 1 else 0 end) from ContractTable ";
            string strEnd = " where ContractNumber = '" + strConditionText + "'";
            strSearch = strSearch + strEnd;
            SqlCommand comm = new SqlCommand(strSearch, cn);
            string strResult = comm.ExecuteScalar().ToString();
            //if (strResult == "1"||strResult =="0")
            if (strResult == "1")
            { args.IsValid = true; }
            else
            {
                args.IsValid = false;
                Response.Write("<script language=javascript>alert('合同号已存在!');</script>");
            }
            cn.Close();
        }
    -------------------------图--------------------------

    C# 菜鸟中的雏鸟!提的问题也许很幼稚,但我是认真的。希望看在党国的面子上拉兄弟一把!

    2013年6月7日 2:41

答案

  • 对不起,你用FormView,应该在ItemUpdating中可以。

    protected void FormView1_ItemUpdating(object senderFormViewUpdateEventArgs e)
            {
                //一般写法:
                FormView1.FindControl("xxx");
                //如果你确定你的编辑状态下某控件绑定了(用Bind),那么:
                e.NewValues["属性或者字段名称"]
            }

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    2013年6月8日 7:54

全部回复

  • 点击编辑界面,请处理RowEditing事件:

    (FormView1.FindControl("xxxx") as SomeControl).SomeProperty……=Some value;


    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    2013年6月7日 2:43
  •     没看懂啊!

    我把前台相关的代码也贴出来吧!该怎么做呢?请帮忙再看看吧!

    <ItemTemplate>
    <asp:Label ID="ContractNumberLabel" runat="server" 
                                                Text='<%# Bind("ContractNumber") %>' />
    <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" 
                                                CommandName="Edit" Text="编辑" Font-Size="16pt" />
    </ItemTemplate>
    
    <EditItemTemplate>
    <asp:TextBox ID="ContractNumberTextBox" runat="server"  BorderStyle="None" BorderWidth="0"  
                                                Font-Size="11px" Height="21px" Text='<%# Bind("ContractNumber") %>' 
                                                Width="99%" />
    <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                                                CommandName="Update" Font-Size="16pt" Text="更新" />
    </EditItemTemplate>


    C# 菜鸟中的雏鸟!提的问题也许很幼稚,但我是认真的。希望看在党国的面子上拉兄弟一把!

    2013年6月8日 1:49
  • FormView_ItemEditing事件。

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    2013年6月8日 2:13
  • 不好意思啊,我是菜鸟。您说的太简单,我实在不知道怎么办。

    C# 菜鸟中的雏鸟!提的问题也许很幼稚,但我是认真的。希望看在党国的面子上拉兄弟一把!

    2013年6月8日 7:16
  • 对不起,你用FormView,应该在ItemUpdating中可以。

    protected void FormView1_ItemUpdating(object senderFormViewUpdateEventArgs e)
            {
                //一般写法:
                FormView1.FindControl("xxx");
                //如果你确定你的编辑状态下某控件绑定了(用Bind),那么:
                e.NewValues["属性或者字段名称"]
            }

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    2013年6月8日 7:54