473,397 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Programmatically Change Text Property of Label in ItemTemplate in Datagrid

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
1 7958
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: DKode | last post by:
Ok, This seems like it should be simple, but everytime I access the label, it's text property is always set to "". Here is the code I am using: private void...
3
by: Dude | last post by:
Below is the code - it is finding the control, and there is no error, just not assigning the text to the label <asp:DataList id="dlGoals" runat="server" onEditCommand="myListEditHandler"...
1
by: Henke | last post by:
Hello, I have one ImageButton controls which I initialize in Page_Load and declare on class level. ImageButton save = new ImageButton(); save.ImageUrl = "save.gif" save.Click += new...
3
by: footballhead | last post by:
Hello- I have page on my site that displays the results of a product search in a datagrid. There is a text field that has a full description of the product named FullInfo. I have placed some...
4
by: John Smith | last post by:
I have DataGrid with Label in one of its columns. Label should change into TextBox, when user do some specific action. How can I acomplish this?? P.S. Sorry for multiple posts in the same...
1
by: Steve Hershoff | last post by:
I'm using VS 2003, and need to extract the text from an asp label in my code-behind file. The label is part of a DataList's ItemTemplate. I've noticed that in my ascx file (we're using User...
2
by: =?Utf-8?B?U3RldmVu?= | last post by:
Hi, I'm new at Visual C++ and I can't figure out how to change the text property of a label. I'm using a char variable that I'd like to assign to the label. Perhaps I should use a System::String^...
2
by: =?Utf-8?B?U2VyZ2lv?= | last post by:
how do i change the text property to a lot of textbox if all textbox are calle textbox1, textbox2 .... instead of doing it one bye one, i mean something like for i as integer = 0 to 10 ...
0
by: Czechtim | last post by:
Hello, I have problem with databinding. I created small application using structure that I need to demonstrate problem. I need to change content of label when changing content of property...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.