ASP.NET Nested Data Bound Controls - asp.net

Say I have a Form View with a Repeater inside of it, and then a Data List nested inside of the Repeater. If I had an Update Command in the DataSource for the Form View would I be able to associate bound values within the Data List to parameters in the Form Views' DS?

You can always go up using .NamingContainer up to the container that has the data you want, and access through .DataItem.
Something around the lines:
((ContainerType)Container.NamingContainer.NamingContainer).DataItem ...

Related

Display data from database without Gridview in asp.net

I am trying to create a page where a list of doctors will appear from my database. But without using the Gridview. I want to display the informations as in the image below. Please help me.image
If you use vb.net...you must use repeater. Other way is iterate data with a for.
Doc for repeater:
https://learn.microsoft.com/en-us/aspnet/web-forms/overview/data-access/displaying-data-with-the-datalist-and-repeater/displaying-data-with-the-datalist-and-repeater-controls-vb
Doc for iterate lists:
https://learn.microsoft.com/es-es/dotnet/visual-basic/language-reference/statements/for-each-next-statement

asp.net webform Repeater, Update a set of textbox, Add to the List / Array

I am working on old webform asp.net application which uses Repeater.
The Repeater is a set of Name and address textbox fields. I have 3 sets of Name and Address information, basically, 3 sets of records in the object list to bind.
On the UI, I changed/update one of the Name and Address. I noticed in the list, which it iterate or loops through the repeater control
foreach (RepeaterItem item in this.NameAddressRepeaterControl.Items)
I see that an extra recod is added to the items.
Question:
I am used to fixed textboxes. When I update the textbox, I write code to take Exactly what is filled in the textbox and populate the DTO object to pass to the data layer to perform database transaction to update the database records.
When the new updated record is added to the Repeater Control list, I don't know which records is updated and which is the new records.
I am checking out OnItemDataBound and OnItemCommand to see if there is a way to get the old value from one of the field and also record the value of the new value. Is this possible?
The form contains 1 Save button and it will loop through the Repeater.Items to see what Name/Address to extract, but the new and old company exist in this list.
Instead of looping through the RepeaterControl.Items, Is there a way to extract from directly the visible Repeater control? If there are 3 repeater Name/Address control, is there a way to get all the info from each of the 3 sets of Repeater controls? The Repeater wraps around a user control, NameAddressCtrl.
I prefer not to replace the Repeater controls with fixed textboxes.
Any help is greatly appreciated.
Thanks.
I reviewed the code several time and add additional code to keep track what was add and changed in the repeated and only passed the information to be saved to the db. The solution was to write additional code. I did not change anything with the repeater behavior. Thanks for the comments and help.

Using GROUP BY with SQLDataSource

I have a SQLDataSource in an ASP.NET Web Form, bound to a GridView and would like to perform a GROUP BY on the underlying data after it has been bound.
I would like the grouped data to appear in a separate GridView.
How would I accomplish this task?
would like to perform a GROUP BY on the underlying data after it has
been bound.
You cannot do that. Once the data is bound, it is bound. The same data will be displayed in the gridview however it was pulled in query with out without grouping. You cannot change it afterwards.
I am thinking you want something different as your question suggests. You want to be able to group on the fly depending on what field the user select. For that you will need different set of controls. May be a dropdownlist and a Gridview Combination? That will be a different scenario.
You can also bound sql datasource on the fly in C# code rather than in ASP.NET code. In that you would be able to achieve it with some additional controls like if this button is clicked, group by this field or if that button is clicked, group by that field.

How can I bind data to an ASP.NET Web Form report?

I have a report 'defined' as a Web Form (aspx). It is divided into what I have classed as sections, where each section has a heading, optional description, and then either tables (GridViews), charts (user controls with asp:Chart controls), or details (in e.g. HTML definition lists). Currently the report is explicitly populated, i.e. code in Page_Load assigns the DataSource property and calls DataBind on GridViews and Charts, explicitly assigns scalar values to label controls for detail sections.
I would like to build a single data set type object (initially an untyped DataSet, but eventually any object graph) and assign this to a DataSource property on the whole report, and call the report's DataBind method. This should delegate data binding to report sections, e.g. I set the DataMember property on my report's PropertyDetails section to "PropertyDetails", so that the PropertyDetails section renders report values from the "PropertyDetails" data table in my big report data set.
How should I structure my Report page (or Control) to facilitate this? I would ideally like a declarative structure similar to the GridView or DataList control, but without a repeating element, i.e. each report section is different, unlike 'rows' in a GridView or DataList; in fact more like Columns in a GridView.
After wrapping your data into a DataSet simply inherit your Report from the BaseDataBoundControl class.
Then you can DataBind to it directly.

Bind a Text Box to a Field Selected by SQLDataSource (VB.NET)

I'm looking for the easiest way to bind data from a SqlDataSource to textboxes dropped in Visual Studio 2008.
For example, I have 4 textboxes currently that have Address, City, State, Zip. I also have a SqlDataSource on the page fetching the ID of the record and selecting those 4 fields based on ID.
How am I able to quickly bind each box to those particular fields selected? I would think this would be really straight forward - but seems it's not. Seems like the answer is funneled towards having to create a GridView or some type of control.
Be gentle...I'm a nub :)
In general you are correct, if you want to use databinding you'll need to use an appropriate control. For this example I'd suggest using a FormView - it is designed to display the results from a single database record and uses templates, meaning you'll have complete control over the output. This article is probably a good place to start: FormView Control: Step by Step.
To read the values bound to the FormView in the code-behind class you would need to create an event handler for the FormView's DataBound event. In that event handler you would reference the controls programmatically via FindControl, like so:
Dim myLabel As Label = CType(FormViewID.FindControl("id"), Label)
Here, id would be the ID of the Label whose value you were interested in. Once you have a reference to the Label you can get its value using myLabel.Text.

Resources