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.
Related
I am working in a project and my Requirement is such that i need to used a Gridview Control as a Templatefield for another Gridview Control and Bind a Generic List to it Dynamically Before Rendering it to User. Is there any way to Bind Child Gridview (Inside Templatefield)?
Lets say:
Parent Gridview: PGridview
Child Gridview: CGridview
I am Really Confused how the PGridView.Databind() will work in this case.
which GridView to bind First and how?
Please Help.
Thanks
In this issue , please verify that on which field relationship are maintain between
Parent Gridview: PGridview and Child Gridview: CGridview
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....
I have an ASP.net repeater that contains a DropDownList inside the <ItemTemplate>. I would like to bind all of the DropDownLists to a single data source:
List<Status> statusList = QuoteRequestLogic.Instance.GetQuoteRequestStatusList();
I know that I can attach to the ItemDataBound event of the repeater, find the DropDownList, and bind it to my List<Status>. Is this the most efficient method? If not, what is?
Thanks in advance!
It is probably the best possible way to achieve what you want I think
In ASP.NET, using a GridView control. Assume my SQLDataSource has an ID, Name and Address. I am only showing Name and Address in the grid, but I want to read the ID every time a row is databound to the grid. How would I do this?
Thanks
The best way in these scenarios is to set the DatakeyName of your ID column in the GridView.
You may use it later on where you need DataKeyNames="ID"
You can bind the ID to a hiddenfield or to any control and make that control's visible property false.
What you need to do is get access to the underlying DataViewRow Object through the Gridview's RowDataBound Event. Once you have the DataViewRow you have access to the DataItem object this is the actual object your GridView is bound to. MSDN has an example here.
Cheers
I have a repeater control that contains an ItemTemplate containing a databound label and a DropDownList control. With each iteration, I'd like to change the ID of the DropDownList with each iteration, in order to use the values as inputs upon submission. Can anyone tell me how this is usually done? Thanks.
This is done for you automatically, see the Using the NamingContainer Property to Determine a Control's Naming Container for details on how it works.
I imagine that probably isn't exactly what you are looking for though. In order to get the values from the drop downs, you should loop through the items in the repeater and use the FindControl method to find the drop down based on the ID you specified.
foreach(RepeaterItem item in repeater1.Items) {
DropDownList dropdown = (DropDownList)item.FindControl("DropDownList1")
//dropdown.SelectedValue
}
Edit: Based on your comment, I would not renamed the drop down list to be the ID in your database. Instead you should put a hidden literal control in your repeater. Set the value of that to the ID of your database record. Then get the ID the same way you get the value of the drop down list.
(Literal)item.FindControl("ListeralWithDataBaseId")
Your aspx markup will look like this
<asp:Literal runat="server" id="ListeralWithDataBaseId"
Value='<%# Eval("Id")' %> Visible="false" />
I found it easiest to just put a PlaceHolder in the Repeater, then create the DropDownList controls at design-time, rather than trying to create one at design-time and changing the ID as it iterates.