Getting changes to the data from a repeater control
-
I have a repeater control that is populated with values from a database every minute. This was done using an AJAX timer and update panel. This all works. What I would like to do is when a new row is added to the repeater control(presumably from someone adding a new row on a copy of the app elsewhere) and it is displayed in the repeater. To find someway of highlighting that row to show it is new. Breaking it down I need to find someway of recognising that the data in the repeater has been changed, then I need a way of highlighting it. Can anyone help?? I was thinking of possibly attempting to populate a dataset from the data contained in the repeater, then databinding the repeater then reloading the dataset with the changes and calling get changes. But I dunno what I am doing and I can’t get this to work and the only way I know how to use a dataset is with a datadapter which I don’t think will work? I have never used datasets before and I can’t really find much help for it on the msdn. If anyone can tell me how to do this it would be most appreciated. Cheers Ian
-
I have a repeater control that is populated with values from a database every minute. This was done using an AJAX timer and update panel. This all works. What I would like to do is when a new row is added to the repeater control(presumably from someone adding a new row on a copy of the app elsewhere) and it is displayed in the repeater. To find someway of highlighting that row to show it is new. Breaking it down I need to find someway of recognising that the data in the repeater has been changed, then I need a way of highlighting it. Can anyone help?? I was thinking of possibly attempting to populate a dataset from the data contained in the repeater, then databinding the repeater then reloading the dataset with the changes and calling get changes. But I dunno what I am doing and I can’t get this to work and the only way I know how to use a dataset is with a datadapter which I don’t think will work? I have never used datasets before and I can’t really find much help for it on the msdn. If anyone can tell me how to do this it would be most appreciated. Cheers Ian
Assuming you have control over the database, I'd be tempted to look at adding a "LastUpdated" datetime field to the database table, and then using the OnItemDataBound event to check for this during binding, and highlighting rows that have been updated in the past X mins/hours/whatewver.... cheers Fred
-
Assuming you have control over the database, I'd be tempted to look at adding a "LastUpdated" datetime field to the database table, and then using the OnItemDataBound event to check for this during binding, and highlighting rows that have been updated in the past X mins/hours/whatewver.... cheers Fred
Ok then didn't think of it that way! :D I have added a column into the table the repeater is created from. the onItemDataBound event is called ItemDataBound? I assume this is the one that you mean? Now sorry to be so dim but I am not sure how I am supposed to get the data in my Column out? I am using this
Protected Sub repResults_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles repResults.ItemDataBound If repResults.Items.Count > 0 Then e.Item.... ' Dunno what goes here? :-S End If End Sub
Ok then I assume that this is where I put my code to check the time compared to the stored time. Only really want those items created in the last 5 mins to be highlighted. But i am a bit clueless as to how to get my the exact item out and how to then go about highlighting the row(I assume its a case of background.color.) The other thing is does the even ItemDataBound get called for each cell in the repeater or is it each row? couldn't find that out anywhere? :doh: Thanks for your help so far tho...excellent idea, just wish i could pull it off! :D Cheers Ian -
Ok then didn't think of it that way! :D I have added a column into the table the repeater is created from. the onItemDataBound event is called ItemDataBound? I assume this is the one that you mean? Now sorry to be so dim but I am not sure how I am supposed to get the data in my Column out? I am using this
Protected Sub repResults_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles repResults.ItemDataBound If repResults.Items.Count > 0 Then e.Item.... ' Dunno what goes here? :-S End If End Sub
Ok then I assume that this is where I put my code to check the time compared to the stored time. Only really want those items created in the last 5 mins to be highlighted. But i am a bit clueless as to how to get my the exact item out and how to then go about highlighting the row(I assume its a case of background.color.) The other thing is does the even ItemDataBound get called for each cell in the repeater or is it each row? couldn't find that out anywhere? :doh: Thanks for your help so far tho...excellent idea, just wish i could pull it off! :D Cheers IanYou'll want something like this in your ItemDataBound event handler: If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then Dim dr As DataRow = e.Item.DataItem.Row, DataRowView Dim d as Date = CDate(dr("LastUpdate")) ' now compare this time with "Now" and if within appropriate time-frame, highlight row... End If It gets called for each row... How you then highlight the row is another matter...! I'm pretty sure I've seen articles on CP about this... or Google it - the answer is out there... cheers Fred
-
You'll want something like this in your ItemDataBound event handler: If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then Dim dr As DataRow = e.Item.DataItem.Row, DataRowView Dim d as Date = CDate(dr("LastUpdate")) ' now compare this time with "Now" and if within appropriate time-frame, highlight row... End If It gets called for each row... How you then highlight the row is another matter...! I'm pretty sure I've seen articles on CP about this... or Google it - the answer is out there... cheers Fred
I have ended up not doing it that way! sorry... sorry i have left work now so I don't have the exact code in front of me so will prob make a mistake ;) in the tag in the html on the repeater I have added > then in the code behind added a function
Function highlightNewRow(ByVal dt as String) as String ' in here i then converted dt to a datetime and got the time as now into ' another variable. if (dt_now - dt_dat) < New Timespan(0, 5, 0) then Return "style='Background:Red;'" 'Realise this is prob wrong, but can't remember what i used in the actual bit I did :) End If Return "" End Function
If you want when i get back into work tomorrow I can post the actual code I used. Thanks for your help tho...it was reading your intial bit about getting the data item back that made me realise I could use the database and do it that way. It was most helpful. Cheers Ian -
I have ended up not doing it that way! sorry... sorry i have left work now so I don't have the exact code in front of me so will prob make a mistake ;) in the tag in the html on the repeater I have added > then in the code behind added a function
Function highlightNewRow(ByVal dt as String) as String ' in here i then converted dt to a datetime and got the time as now into ' another variable. if (dt_now - dt_dat) < New Timespan(0, 5, 0) then Return "style='Background:Red;'" 'Realise this is prob wrong, but can't remember what i used in the actual bit I did :) End If Return "" End Function
If you want when i get back into work tomorrow I can post the actual code I used. Thanks for your help tho...it was reading your intial bit about getting the data item back that made me realise I could use the database and do it that way. It was most helpful. Cheers IanThat's great - it's always good to figure out your own answer! Don't worry about code - I can see what you've done. cheers Fred
-
That's great - it's always good to figure out your own answer! Don't worry about code - I can see what you've done. cheers Fred
Thanks Fred, I only just started a new job and begun learning asp.net as part of it. Never used it before so its a big learning curve for me. I have to say how great a community this is and how friendly people are on here helping misfits like me out! :-) Thanks for taking the time Fred. Cheers Ian