does anyone uses this control and knows how to load data to it from simple datatable. There is not such a trick as DataSource...
Im assuming you just mean a datatable you have created programatically?
It will bind straight up like it would from a DataSource.
Just make sure your DataField name in the columns mark up matches the name of the column and your good to go, just as you would with a different datasource.
Then just do
grvFoo.DataSource = yourProgrammticallyCreatedTable;
grvFoo.DataBind();
But, since your doing this progrmatically I would recommend making a "BindTable" function. Eg a function that builds your datatable and bind. You can then use this for sorting / paging etc. As your doing this all programatically you must handle such events by hand, they are normally done with the SQL / Object Datasource etc.
you mean Telerik Radgrid ? If yes, you can also specify a "NeedDataSource" event in the aspx/ascx
http://www.telerik.com/help/aspnet-ajax/grdadvanceddatabinding.html
On a side note, just to let you know, we are having a lot of performance problems with Telerik. For the most part, you can use the inbuilt asp.net gridview (and do some more styling if needed) than taking a performance hit by using telerik (for their fancy grid)
We must use ItemsSource property like this:
dataGridView1.ItemsSource = LoadDataTable.DefaultView;
LoadDataTable - this is some DataTable, filled from SQL.
Related
This might be a silly question. But I have a lot of textboxes in an in asp.net form I need to populate with data from a sql query.
If the query column names and textbox names are all the same, is it possible to populate the textboxes from the query data automatically? Maybe using loop? There are too many fields so I think it is stupid to populate each field individually using something like:
textboxX.text = data.getValue(0).ToString();
textboxY.text = data.getValue(1).ToString();
...
I am thinking there must be a simpler way to populate all of the textboxes. Can anyone please help me to do this? A simple example would be great.
If you were using something like MVC or MVVM then it would be in a manner of speaking. You could tie your view page to a model that has properties corresponding to the fields. Then in your view page you would bind the model properties to the fields.
If you don't work with MVC/MVVM/knockout then the best thing you could do is to loop your form's controls and assign them some values from your list. For this purpose it's simplier if your controls are named like Ctrl1, Ctrl2, etc - it's just to simplify the looping/assignment
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.
I have a GV and a DV that extract data from the same database. The link between these controls is when a record in the GV is selected, the DV displays more details about that record.
Do I need separate connections? Obviously, I haven't achieved this goal and am working on it. Thanks.
CLARIFICATION so as not to waste your time:
I am asking about connection, not datasource. The reason that I am not sure the same connection can be used is that with GV, the connection doesn't have any parameter. Whereas with the DV, it needs the record ID passed to it. Or am I wrong?
Here's the link to code on the net that makes me wonder:
http://asp.dotnetheaven.com/util/srcview.aspx?path=~/aspnet/samples/data/GridViewMasterDetails.src
I am a novice so am still confused with the terminology. Thanks for being patient.
They can use the same datasource. (Such as an ObjectDataSource or SQLDataSource)
You can use the same data source, i.e. a DataTable. But when the Gridview row is selected you will need to find the index of the selected row and then find the DataRow from the DataTable and rebind your DetailView to that DataRow. Hope this helps.
I think that you are using Visual Studio databinding, and I would say that same Connection(DataSource) object can be used (if that is the way it goes), but I would rather suggest you avoid this design time Visual Studio programming, although it is simple and fast
Can a GridView be bound to a List<>?
I want to create a Master Details scenario. So The first List<> contains Master data and the second Child data. When the user clicks on the Master Data, the child data, should appear in a pop.
Is that possible? Please share some code.
Yes, this is possible. Take a look at the ObjectDataSource to use for databinding a list to a GridView. It requires some more manual coding, but it works.
There's a good discussion of one possible solution here that manually constructs a DataTable from your business object list to make filtering/sorting/paging easier than manually implementing those methods.
You can create on temporary table and then bind that table with grid.
Like,
dataset.DataSource=tempTable;
tempTable.DataBind();
GridView1.DataSource = theList;<br/>
GridView1.DataBind();
I know how to use the checkboxlist in ASP.NET to display options retrieved from a database. What I don't know how to do is to make this 2-dimensional. That is, I need a list of checkboxlists where I don't know how long the list is; both dimensions of the checkboxlist will be determined by
list of people (pulled from database)
list of tasks (pulled from database)
and the user of the web page will click in column/row to specify which people will be assigned which tasks.
Right now I'm thinking that my only option is to brute-force it by creating a table and populate each cell with its own checkbox. (yuck)
Is there a more elegant way to create a 2-dimensional array of checkboxes with labels for both rows and columns?
I would use a repeater along with a checkboxlist. Depending on how your database is setup you could have each checkboxlist databound.
I've done this before and resorted to the brute-force method you suggest.
It's not as nasty as you'd think. Other solutions that were declarative and databound would likely be just as convoluted and confusing.
I use the ASPxGridView from DevExpress. It has a control column type of Selected (or something like that) which will display a checkbox in the column with the other column populated from your bound datasource. The User can select any rows desired by checking the checkbox on the row and you can get all the selected rows easily inot a collection to process. DevExpress components really do get rid of a lot of brute-force programming.
You can programmitaclly use a GridView control. It's inherently two-dimensional and you can use databound CheckBoxFields for it.
If you're looking for a quick and dirty way, you can use the AJAX Control Toolkit with the two controls and can populate one based on the other. If that's not what you're looking for, I'd do it the brute force way.