日期:2014-05-17  浏览次数:20394 次

如何获取FormView模板里的控件
在FormView定义了:
<ItemTemplate>
  Spl_Code:
  <asp:Label ID="Spl_CodeLabel" runat="server" Text='<%# Bind("Spl_Code") %>' />
  <br />
  Spl_Name:
  <asp:Label ID="Spl_NameLabel" runat="server" Text='<%# Bind("Spl_Name") %>' />
  <br />

</ItemTemplate>

请教朋友们,如何在后台获取控件比如CodeLabel:
protected void Button1_Click(object sender, EventArgs e)
 {
   
  lable lb = ((Label)FindControl("Spl_CodeLabel"));
  // lb = null,访问不到,请问朋友们怎么解决,谢谢
lb.Text ="测试";
}
 

------解决方案--------------------
DropDownList ddl= FormView1.FindControl("DropDownList1") as DropDownList;

------解决方案--------------------
你这个Button是在FormView里面的吗?
------解决方案--------------------
DropDownList ddl= FormView1.FindControl("DropDownList1") as DropDownList;
但BUTTON不要在FORMVIEW中
得到的是一个引用,而不是值,修改了ddl则源FORMSVIEW的DROPDOWNLIST控件发生改变!!!
------解决方案--------------------
探讨
DropDownList ddl= FormView1.FindControl("DropDownList1") as DropDownList;

C# 没有这样的用法吧。

Button 在FormView外,是页面上的。

等待交流学习。

------解决方案--------------------
TextBox txt= this.GridView1.Rows[i].Cells[3].FindControl("TextBox2") as TextBox ;
------解决方案--------------------
你的代码好象没什么问题!!

在Page_Load绑定数据时
if(!IsPostBack)了吗??