I have a FormView that has a repeater inside. In order to render the ItemTemplate I do a fake datasource and databind.
Then I look for the Repeater with FindControl and do another DataSource and DataBind.
So in this case HardCodedData is just a placehoder to get me to renter the FormView ItemTemplate.
FormView1.DataSource = HardCodedData;
FormView1.DataBind();
Repeater r = ((Repeater)FormView1.FindControl("repeater1"));
r.DataSource = GetMyData();
r.DataBind();
Is there a better way? Can I just get FormView to renter without giving it fake data? Or can I pass the repeater data through the FormView DataSource?
As a repeater control is inside the form view than you should bind this repeater control inside the form view's event DataBound threw that you will be get exact data which you want to get. Put your following code inside your FormView1_DataBound event.
Repeater r = ((Repeater)FormView1.FindControl("repeater1"));
r.DataSource = GetMyData();
r.DataBind();
May be this solution can help you....
Related
I am trying to figure out what the correct event would be to populate a ComboBox in a Telerik RadGrid or any ASP.NET grid from the CodeBehind. When the user clicks Edit on a row the ComboBox should be populated with its items.
The only examples I have seen are using the DataSourceID property in the aspx page. I prefer doing all of my populating manually in the code behind:
ComboBox1.DataSource = colorList;
Combobox1.DataBind();
You can access child controls in a grid column in:
ItemDataBound - fired for each item (so you need to check for GridDataItem types or GridEditItem, depending on your goal)
ItemCreated - similar, but you don't have the data item object associated with each item
ItemCommand - when Edit is clicked an Edit command is invoked so you can access it.
I've a gridview bound to linqdatasource1 and a details bound to linqdatasource2 (for searching).
When I update the data on detailsview, my gridview is not updating. I've tried handling various gridview events and databinding the gridview in code but it doesn't seem to work.
Perform a .DataBind on the gridview as you manipulate data in the detailview
I want a Repeater control inside a Gridview row. So how can I assign the DataSource of the Repeater control so that the data it uses is that of the specific data of the GridView row?
I tried this:
DataSource='<%# Eval(Container, "DataItem.InnerVal")
but it does not work.
You will need to handle the GridView.RowDataBound event in your code-behind. This will allow you to dynamically create a Repeater and bind it to the data for the row you are on.
go through this: http://www.codeproject.com/KB/database/repeater_in_gridview.aspx
Hope it help you.
I have a ASP.NET page with a FormView control. When the FormView is bound I'd also like to set the Text property of a Label control that is outside the FormView.
What is the best way to do this? I thought about using the DataBinding or DataBound event of the FormView but the EventArgs parameter provided does not seem to give me access to the current values.
The FormView control has a DataItem property. Give the DataBound event another shot.
I have a Repeater inside the TemplateField for a GridView. GridView is bound to datasource1 and the repeater to datasource2. How can i access datasource1 from the ItemTemplate of repeater in data binding syntax (<%# %>) of repeater itemtemplate?
See this question. That question was relevant to Repeaters but you get the idea. The GridView exposes the RowDataBound event which you can handle in the same way.
Of course, I don't believe there is a way to access it via the declarative Databinding syntax.