Click here to Skip to main content
15,998,008 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use FormView like :


C#
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!
Posted

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.
 
Share this answer
 
thank you very much,I can go on,thanks a lot.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900