By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,302 Members | 1,816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,302 IT Pros & Developers. It's quick & easy.

Programmatically Change Text Property of Label in ItemTemplate in Datagrid

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <Cr**********@hotmail.com> wrote in message
news:eU**************@TK2MSFTNGP11.phx.gbl...
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

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.