|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to reach the object connected to repeaterI have a repeater that is connected to an objectdatasource. I can reach the item control like this. foreach (RepeaterItem item in Repeater1.Items) { CheckBox c= (CheckBox)i.FindControl("checkbox1"); Label l = (Label)i.FindControl("label1"); } The objectdatasource have information that i don’t want to show, but i need to reach. One solution is to use controll with Visible set to false, but I don’t like this solution. Is it posible to reach the RepeaterItem dataobject? I have tried this code with no sucsess: foreach (RepeaterItem item in Repeater1.Items) { CheckBox c= (CheckBox)i.FindControl("checkbox1"); Label l = (Label)i.FindControl("label1"); CustomerClass c = (CustomerClass)i.DataItem; } Is there anybody how have an suggestion? Regard Karl-Inge Reknes You can access the dataitem through the repeater items only before the
repeater is rendered during the ItemDataBound event like this: void repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.SelectedItem) { //assuming the repeater is bound to a class named CustomerClass //each DataItem can be cast to that class and then the properties //can be accessed string FirstName = ((CustomerClass)e.Item.DataItem).FirstName; } } But if you want to update the data after some user entries are done on the repeater-rendered controls, e.g. the user changed the checkboxes state, then you will have to retrieve the data records from the data store and locate the individual rows using their primary keys. Show quoteHide quote "Karl-Inge Reknes" wrote: > Hi > > I have a repeater that is connected to an objectdatasource. I can reach the > item control like this. > > foreach (RepeaterItem item in Repeater1.Items) > { > CheckBox c= (CheckBox)i.FindControl("checkbox1"); > Label l = (Label)i.FindControl("label1"); > } > > The objectdatasource have information that i don’t want to show, but i need > to reach. One solution is to use controll with Visible set to false, but I > don’t like this solution. > > Is it posible to reach the RepeaterItem dataobject? > > I have tried this code with no sucsess: > > foreach (RepeaterItem item in Repeater1.Items) > { > CheckBox c= (CheckBox)i.FindControl("checkbox1"); > Label l = (Label)i.FindControl("label1"); > CustomerClass c = (CustomerClass)i.DataItem; > } > > Is there anybody how have an suggestion? > > Regard > Karl-Inge Reknes >
"Cannot have multiple items selected in a DropDownList" Error
How to get ListItemValue and ListItemText from a Combo using SendMessage edit attribute values of a web control just before control rendered to the page (control's Load even RE: Checkbox data binding on Checked property Accessing FormView template controls clicked event never fires Atlas UpdatePanel with Webparts events inheritance Problems with dynamically created GridView/DetailsView validating user control |
|||||||||||||||||||||||