开发者

BindData to ITemplate for GridView in code behind

How do I programmatically bind data to a custom item template column for a GridView? So far, I've done something similar to this:

        TemplateField foo = new TemplateField();
        foo.ItemTemplate = new bar();
        this.GridView1.Columns.Add(foo);

where bar is like this:

public class bar : ITemplate
{
    public bar()
    {

    }

    public void InstantiateIn(Control container)
    {
        DropDownList ddl = new DropDownList();
        container.Controls.Add(ddl);
    }
}

(the actual dropdownlist is populated)

But ITemplate doesn't contain any kind of data binding properties to implement, and the TemplateField class doesn't seem to have any either...

What do I do?


Edit: The other half is being able to handle th开发者_开发问答e updates to get back to the original datasource. If I just handle the rowupdate events, I don't see my TemplateColumn in the oldvalues/newvalues lists.


You handle the GridView.RowDataBound event.

This explains things... http://www.aspnettutorials.com/tutorials/controls/dropdownlist-gridview-csharp.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜