FormView DataBinding数据如何 [英] How FormView DataBinding Data
问题描述
我像这样使用FormView:
公共 void InstantiateIn(System.Web.UI.Control容器)
{
PlaceHolder hp = 新 PlaceHolder();
lb = 新 Label();
li.ID = " ;
c.Controls.Add(lb);
hp.DataBinding + = 新 EventHandler(DoyenForm_DataBinding);
container.Controls.Add(hp);
}
私有 无效 DoyenForm_DataBinding(对象发件人,EventArgs e)
{
ph =(PlaceHolder)sender;
IDataItemContainer ri =(IDataItemContainer)ph.NamingContainer;
对象 itemValue = 空;
itemValue = DataBinder.Eval(ri.DataItem," );
((TableCell)ph.FindControl(" )).Text = itemValue.ToString();
}
它不起作用:
((TableCell)ph.FindControl("S_SpcName")).Text = itemValue.ToString
感谢您的答复!
lifanvc写道:li.ID ="S_SpcName;
您为 LABEL 控件
定义了名称"S_SpcName"
lifanvc写道:(((TableCell)ph.FindControl("S_SpcName")).Text = itemValue.ToString();
您正在尝试获取此标签控件的值,但将其强制转换为TableCell!那就错了...
Findcontrol并将其转换为它的原始形式以访问值.
此外,您共享的代码中的所有名称都不会写入.您将"hp"用作占位符,但将控件lb添加到某些"c"(未定义)中
然后,您将"lb"添加为新标签,但将一个ID分配给"li"(再次未定义)=>我会在此处而不是在您的应用程序中共享代码时承担所有这些错误.
非常感谢,我可以继续,非常感谢.
>
I use FormView like :
public void InstantiateIn(System.Web.UI.Control container)
{
PlaceHolder hp = new PlaceHolder();
lb = new Label();
li.ID = "S_SpcName";
c.Controls.Add(lb);
hp.DataBinding += new EventHandler(DoyenForm_DataBinding);
container.Controls.Add(hp);
}
private void DoyenForm_DataBinding(object sender, EventArgs e)
{
PlaceHolder ph = (PlaceHolder)sender;
IDataItemContainer ri = (IDataItemContainer)ph.NamingContainer;
object itemValue = null;
itemValue = DataBinder.Eval(ri.DataItem, "S_SpcName");
((TableCell)ph.FindControl("S_SpcName")).Text = itemValue.ToString();
}
it''s not work:
((TableCell)ph.FindControl("S_SpcName")).Text = itemValue.ToString
Thanks for your replying!
lifanvc wrote:li.ID = "S_SpcName";
You defined a name ''S_SpcName'' to a LABEL control
lifanvc wrote:((TableCell)ph.FindControl("S_SpcName")).Text = itemValue.ToString();
You are trying to get this label control''s value but casting it into a TableCell! Thats wrong...
Findcontrol and cast it into it''s original form to access the values.
Further, all your names in code shared are not write. You use ''hp'' for placeholder but add control lb to some ''c'' (not defined)
Then you add ''lb'' as new label but assign an ID to ''li'' (again not defined) => i assume all those mistakes while sharing code here and not in your application.
thank you very much,I can go on,thanks a lot.
这篇关于FormView DataBinding数据如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!