WEB开发网
开发学院WEB开发ASP.NET .net中如何用findcontrol获得GridView自定义控件的... 阅读

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

 2010-07-13 17:42:57 来源:WEB开发网   
核心提示:问:要获得MAmount的值如何获得<asp:TemplateField HeaderText="数量" SortExPRession="MAmount" HeaderStyle-Width="150"> <ItemTemplate>

问:
要获得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 { }
   }

Tags:net 如何 findcontrol

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接