Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > DataBind code equivalent of Text='<%# Bind("MyColumn") %>' of Item Template in GridView

Reply
Thread Tools

DataBind code equivalent of Text='<%# Bind("MyColumn") %>' of Item Template in GridView

 
 
Desmond Cassidy
Guest
Posts: n/a
 
      04-07-2007
Hi,
ASP.NET 2.0

I am trying to get a handle on writing the GridView's attriburtes in the code behind page.

I am using a class which implements the ITemplate.InstantiateIn and have successfully

1. Created most types of controls
2. Associated them with ItemTemplate, FooterTemplate etc.
3. Add to the Columns of the Grid.

The code is reasonably straight forward.
For Each Column of the Grid
a) Create a Template
b) Create a collection of WebControls
c) Associate them with each other through the ITemplate implemented class

However, whilst creating some controls there is a need to have the databinding attributes set against the Text properrty of e.g a Label Control.
So, in the ASP page we have something like...

<asp:GridView ID="MyGenericGrid" runat="server" ShowFooter="True">

<Columns>

<asp:TemplateField HeaderText="ProductID" InsertVisible="False" SortExpression="ProductID">

<ItemTemplate>

<asp:Label ID="Label1" runat="server" Text='<%# Bind("ProductID") %>'></asp:Label>

</ItemTemplate>

<ItemStyle HorizontalAlign="Center" />

<FooterTemplate>

<asp:Button ID="AddProduct" runat="server" CommandName="Insert" Text="Add" />

</FooterTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

Now I have succesfully done all but the Text: in the Label. Question therefore - what is the way of coding Text='<%# Bind("ProductID") %>' in the code behind page - I have seen some code on various websites with bound fields and Databind.Eval but fail to understand what's going on ??? Suffice to say that the follwoing code does not work (i.e. doesn't BIND !) when I pass the quoted text above to the function.

Private Function CreateLabel(ByVal ID As String, ByVal Text As String) As Label

Dim lLabel As New Label

lLabel.ID = ID

lLabel.Text = Text

Return lLabel

End Function





 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
databind dataset to gridview in gridview mharness ASP .Net 2 06-29-2007 11:38 AM
GridView add multiple controls to edit item template =?Utf-8?B?SmVyb2QgSGF0bGV5?= ASP .Net 2 10-08-2006 03:04 PM
How to Add new Item into DropDownList after DataBind with Database ? Kylin ASP .Net 1 04-23-2005 08:58 AM
e.Item.DataItem gives Null Reference after DataBind Kel Good ASP .Net 2 04-25-2004 09:47 PM
BUG in DataBind? After .DataBind there are more DataGrid Items than DataSet Rows! Michael ASP .Net Datagrid Control 0 12-29-2003 07:47 PM



Advertisments