Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Programmatically Change Text Property of Label in ItemTemplate in Datagrid

Reply
Thread Tools

Programmatically Change Text Property of Label in ItemTemplate in Datagrid

 
 
Craig
Guest
Posts: n/a
 
      10-08-2004
How do I programmatically change the text property of a label in an
ItemTemplate in a datagrid?
Specifically the Text property. I want to change the databinding to another
column at runtime.

<asp:TemplateColumn HeaderText="Rate1">
<ItemTemplate>
<asp:Label runat="server" Text='<%# fRate(DataBinder.Eval(Container,
"DataItem.RateAgentID")) %>' ID="Label3" NAME="Label3">
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>

Thanks


 
Reply With Quote
 
 
 
 
Karl
Guest
Posts: n/a
 
      10-09-2004
Hook into the ItemDataBound event of the datagrid, then:

Label lbl = (Label)e.Item.FindControl("Label3")
if (lbl != null){
lbl.Text = ((DataRowView)e.Item.DataItem)["OtherColumn"]
}

DataItem actually returns an object which will be a DataRowView when binding
to a dataset/datatable/datarow...looks like you are binding to a custom
collection in which case it'll return your collection item type:

lbl.Text = ((YourClassEntity)e.Item.DataItem).YourProperty

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


"Craig" <(E-Mail Removed)> wrote in message
news:eUJz$(E-Mail Removed)...
> How do I programmatically change the text property of a label in an
> ItemTemplate in a datagrid?
> Specifically the Text property. I want to change the databinding to

another
> column at runtime.
>
> <asp:TemplateColumn HeaderText="Rate1">
> <ItemTemplate>
> <asp:Label runat="server" Text='<%# fRate(DataBinder.Eval(Container,
> "DataItem.RateAgentID")) %>' ID="Label3" NAME="Label3">
> </asp:Label>
> </ItemTemplate>
> </asp:TemplateColumn>
>
> Thanks
>
>



 
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
ItemTemplate: How to create a Hyperlink with a Text property binded with a ObjectDataSource RenatoGuarilha ASP .Net Web Controls 1 01-19-2006 02:08 PM
assigning itemtemplate, edititemtemplate programmatically Steve P ASP .Net Datagrid Control 3 03-30-2005 12:53 PM
Programmatically Change Text Property of Label in ItemTemplate in Datagrid Craig ASP .Net Datagrid Control 1 10-09-2004 12:36 AM
Programmatically Change Text Property of Label in ItemTemplate in Datagrid Craig ASP .Net 1 10-09-2004 12:36 AM
can code inside a Repeater's ItemTemplate modify controls in the ItemTemplate? Bennett Haselton ASP .Net 1 09-24-2004 01:59 AM



Advertisments