Changing text of a label inside a control...

B

bredal Jensen

Hello there,

I need to change the text of a label inside a datagrid.
The label is part of an <EditItemTemplate >

Can anyone post code of how to do this?

Many thanks
 
J

Juliet Choy

You have to give an ID to your Label Control, say "Label1", then you can
change your text by using the OnItemDataBound event:

private void DataGrid1_ItemDataBound(object sender,
DataGridItemEventArgs e) {
if(e.Item.ItemType == ListItemType.EditItem) {
Label l = (Label)e.Item.Cells[colNum].FindControl("Label1");
l.Text = "Your desired text";
}
}

Hope this help you.
Regards,
Juliet Choy
Hong Kong
Microsoft MVP - ASP.NET
 
B

bredal Jensen

Right , great help... Thanks a lot
Juliet Choy said:
You have to give an ID to your Label Control, say "Label1", then you can
change your text by using the OnItemDataBound event:

private void DataGrid1_ItemDataBound(object sender,
DataGridItemEventArgs e) {
if(e.Item.ItemType == ListItemType.EditItem) {
Label l = (Label)e.Item.Cells[colNum].FindControl("Label1");
l.Text = "Your desired text";
}
}

Hope this help you.
Regards,
Juliet Choy
Hong Kong
Microsoft MVP - ASP.NET

bredal said:
Hello there,

I need to change the text of a label inside a datagrid.
The label is part of an <EditItemTemplate >

Can anyone post code of how to do this?

Many thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top