Can the devexpress Gridview Control be used completely in unbound mode? - devexpress

I want to use the Aspx gridview with out connect it to datasource

From: Add new unbound row in bound AspxGridView
The ASPxGridView can't display unbound rows. As a possible solution,
create an intermediate in-memory datasource (e.g. DataTable), copy
rows from your read-only datasource into it, and bind it to the grid.
Then, you'll be able to programmatically add new rows to this
datasource.
You can manage in memory DataSet(other datasource types), to populate data in the grid. There are lots of DevExpress threads about such type of requirements. I suggest you to go through them and implement in the way that you like to prefer.
ASPxGridView - How to manipulate data without data source
aspxgridview without datasources
Add new unbound row in bound AspxGridView

Related

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.

Please anyone give me idea how to populate two result sets into gridview

I have two stored procedures which gives Daily swipe data and another gives Temporary Swipe details.
I got an requirement to populate gridview, Based on the date the temporary card details must get displayed in between Daily swipe data.
Please anyone give me idea how to populate two result sets into gridview
Iam using Sql server 2008 R2 and Visualstudio 2010
Lets assume we consume this ResultSet which has two DataTables "Agent" and "RealEstateProperty". The task is to display, what properties belongs to which agent, in a GridView.
There are different ways to accomplish this task-
Method 1: Bind DataTables to a single GridView
To bind these multiple DataTables to a single GridView control, we can quickly create a new temporary DataTable, with the required fields and populate the Rows and then bind the new DataTable Rows to the GridView.
The above code is self explanatory, where I have created a temporary DataTable, populated its rows by iterating through the original DataTables and then binded the Grid to the new DataTable.Rows. The interesting piece of code to note here is the row.GetChildRows(), which respects the relationship and automatically returns the related child rows. The aspx part looks like the following, where we have a GridView with three columns.
and the RowDataBound code is
Method 2: Bind DataTables to a nested GridView
If we want to avoid creating temporary dummy DataTable as described in method 1, we can use the technique of nested list control. Now we can do this by using
two GridView, or
two DataList, or
two Repeaters or
a combination of Repeater and GridView, or
a combination of Repeater and DataList, or
a combination of GridView and DataList.
We are going to look at a combination of 2 GridViews here, where one GridView is nested inside another, you can do any of the above combinations. For this case the the aspx code is-
Notice the parent and nested GridViews has different onrowdatabound methods. In this technique the parent grid is binded to the the Agent DataTable Rows and the nested GridView is binded to the child RealEstateProperty DataTable Rows. Here is the code.
Method 3: Convert the DataSet to Objects and then bind to GridView
We can generate csharp class from the dataset schema using Xsd.exe and then bind the GridViews to the objects. I have discussed similar technique in one of my previous blog post, where you will find how we can use the Xsd.exe that ships with the .NET Framework.
Example
C:\temp>xsd propertyDataSet.xsd /l:cs /c
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation. All rights reserved.
Writing file 'C:\temp\propertydatasetclass.cs'.
I also demonstrated a handy DataTableToT() method to assist in converting DataTable to strongly typed object. And when we have the DataTable converted to a stronglytyped object/list/collection it is very easy to bind to the bind to the GridView.
1.Call your Second stored procedure within first stored procedure.
2.Pass your outcome to dataset.
3.From dataset u can fetch it using ds.table[0],ds.table[1],etc..
you can find from here, Merging DataSet Contents
http://msdn.microsoft.com/en-us/library/aszytsd8.aspx

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.

Is it possible to have a SQLDataSource with a parameter that is based only upon the GridView that is binding to it?

I have a scenario where I want to put four identical Gridviews on the same page. (They will be on different tabs in an Ajax TabControl.) They show the same source data, but there are four corresponding groups of source data in a common underlying table. So I want to show Group 1 on Tab 1, Group 2 on Tab 2, etc. These Gridviews contain complicated controls, so I would prefer to use the same data source for all of them to avoid unnecessary repetition. The Insert and Update commands are completely identical.
So in theory I could build the Select command in such a way that I could filter the data based on the GridView that is binding to the SQLDataSource. The problem is that if I use the same SQLDataSource for all the Gridviews, I cannot find a way to have each GridView tell the SQLDataSource which one is calling it. I am thinking maybe this is not possible, because the SQLDataSource binds first before it knows what is binding to it, but I'm not sure. Can anyone think of a way to do this?
You can change the parameter value dynamically using OnSelecting event of SQLDataSource. This can be done in server side code.
Create a property which holds your current gridview unique key, which is causing SQLDataSource to fetch data from SQL database.
Assign this property unique gridview key on DataBinding event of gridview.
Based on this property change the parameter in OnSelecting event of SQLDataSource.
Let me know if I am missing something.

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