博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

.net中如何用findcontrol获得GridView自定义控件的值

Posted on 2010-09-08 01:30  赖鱼塘  阅读(1121)  评论(0编辑  收藏  举报

问:
要获得MAmount的值如何获得
<asp:TemplateField HeaderText="数量" SortExPRession="MAmount" HeaderStyle-Width="150">
      <ItemTemplate>
         <my:SelectNumber ID="MAmount" runat="server" Value='<%#Bind("MAmount") %>'   />
      </ItemTemplate>
    </asp:TemplateField>
问题补充:要将GridView中的数据批量修改,用FindControl获得<my:SelectNumber ID="MAmount" runat="server" Value='<%#Bind("MAmount") %>'   />的值
cmd.CommandType = CommandType.Text;
                cmd.CommandText = "update yf_Purchases set Main=@Main, MAmount=@MAmount,MOverDate=@MOverDate,MMPrice=@MMPrice where OrderID=@OrderID";
                cmd.Parameters.Add("@OrderId", SqlDbType.NVarChar, 20);
                cmd.Parameters.Add("@Main", SqlDbType.NVarChar, 10);
                cmd.Parameters.Add("@MAmount", SqlDbType.Int);
                cmd.Parameters.Add("@MOverDate", SqlDbType.VarChar,50);
                cmd.Parameters.Add("@MMPrice", SqlDbType.Int);
                cmd.Parameters["@OrderId"].Value = ((HiddenField)gvr.FindControl("OrderID")).Value;
                cmd.Parameters["@Main"].Value = ((TextBox)gvr.FindControl("Main")).Text;
cmd.Parameters["@MAmount"].Value =?

 

答:
例子:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.Cells[12].Text.ToString() == "提交待审核" || e.Row.Cells[12].Text.ToString() == "审核通过")
            {
                Label lbl_edit = e.Row.FindControl("Label1_edit") as Label;
                Label lbl_editr = e.Row.FindControl("Label1_editr") as Label;
                lbl_edit.Visible = false;
                lbl_editr.Text = "      ";
                lbl_editr.Visible = true;
            }
        }
        catch { }
    }