l_agmon
asked on
DataList - Updateing a Label in ItemTemplate from an "Update" command
Hi,
Can I somehow solve the following situation? :
I a datalist, the user presses Edit. The <EditItemTemplate> become visible. The user then presses 'Save' - and the UpdateCommand is being called.
After I update the relevant data, I return to the list (i.e., items are presented as <ItemTemplate>).
What I want to do is to make a label in <ItemTemplate> become visible, upon the use pressing 'Save' in the <EditItemTemplate>. Is that possible?
I tried to create a Label called MessageLabel in the <ItemTemplate>, and in the UpdateCommand have the following line:
((Label) e.Item.FindControl("Messag eLabel")). Visible=tr ue;
It doesn't work - I suspect because the "e" variable contains only the controls of <EditItemTemplate>.
Thanks !
Agmon.
Can I somehow solve the following situation? :
I a datalist, the user presses Edit. The <EditItemTemplate> become visible. The user then presses 'Save' - and the UpdateCommand is being called.
After I update the relevant data, I return to the list (i.e., items are presented as <ItemTemplate>).
What I want to do is to make a label in <ItemTemplate> become visible, upon the use pressing 'Save' in the <EditItemTemplate>. Is that possible?
I tried to create a Label called MessageLabel in the <ItemTemplate>, and in the UpdateCommand have the following line:
((Label) e.Item.FindControl("Messag
It doesn't work - I suspect because the "e" variable contains only the controls of <EditItemTemplate>.
Thanks !
Agmon.
ASKER
I am afraid this will not work - as each datalist can contain many records, and setting a single viewstate variable is not enough.
There are a couple of things going on. But the main problem is as follows
The message label is within the ItemTemplate, but the UpdateCommand fires in the EditItemTemplate. What you need to do:
1) databind the updated datasource to the datalist
2) find the row you were in
3) show the message label
Pseudocode:
Dim iMyIndex Int32 = YourList.EditItemIndex
YourList.EditItemIndex = -1
DataBind()
Dim CurrentItem as DataListItem = YourList.Items.Item(iMyInd ex)
CurrentItem.FindControl("M essageLabe l").Visibl e=true;
The message label is within the ItemTemplate, but the UpdateCommand fires in the EditItemTemplate. What you need to do:
1) databind the updated datasource to the datalist
2) find the row you were in
3) show the message label
Pseudocode:
Dim iMyIndex Int32 = YourList.EditItemIndex
YourList.EditItemIndex = -1
DataBind()
Dim CurrentItem as DataListItem = YourList.Items.Item(iMyInd
CurrentItem.FindControl("M
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
bool bLabelVisible
{
set {ViewState["LabelVisible"]
get {return (bool)ViewState["LabelVisi
}
In OnPageLoad when there is not postback (first call to page) set bLabelVisible to false;
if (!IsPostBack)
{
...
bLabelVisible = false;
}
In UpdateCommand set bLabelVisible to true:
bLabelVisible = true;
in OnItemDataBound event add:
if (e.Item.ItemType == ListItemType.ItemTemplate || e.Item.ItemType == ListItemType.AlternatingIt
{
((Label) e.Item.FindControl("Messag
}