I have an UltraWebGrid bound to a Data Source...
At this point, the entire Grid I created is controlled through choices I have made in the Designer. (Of course, I can do some coding if necessary).
I would like to assign a "DefaultValue" for a particular column so that when a new row is added that column takes on the current DateTime (the column is "DateAdded"...duh...). Inside the Designer the "DefaultValue" is greyed out and i am unable to type anything there. Can someone tell me how to accomplish what I am trying to do? (If I can do it in the designer, that would be nice, if not I can do "code behind". I will be using C#.)
And while I am asking, is there an easy way to enable "CRUD" (Change, Upade, Detele) in the UltraWeb Grid or do I need to add a button for saving? I found the "add" button to add new rows and enabled the grid to allow column cahnges, etc. I just cant get the data to actually save. :)
Thanks for any adivce!Shayne
I tried everything I could think of to get the designer to accept a DefaultValue, with no luck. (Hopefully, an Infragistics staff member will chime in the help on that.)
I did find an article in the Online Docs that shows how to set a DefaultValue in the the code-behind. I didn't try it. The online docs are at http://help.infragistics.com/NetAdvantage/NET/2008.2/CLR2.0/ but the navigation scheme there is klunky. The article in question is here: (click here)
in UltraWebGrid1_InitializeLayout event using
e.Layout.Bands(0).Columns.FromKey("JobID").DefaultValue =
Hello,
DefaultValue cannot be set declaratively in the ASPX or in the designer because it is of type object - there is no way you can tell at design time what value gets there (it is a generic object) so the only way to specify it is programmatically. The code samples above seem pretty good to me, InitializeLayout is a great event to place such code there.
The CRUD operations can be enabled using the Allow... properties on the display settings, for example:
<displaylayout bordercollapsedefault="Separate" name="UltraWebGrid1" AllowDeleteDefault="Yes" AllowUpdateDefault="Yes" AllowAddNewDefault="Yes"
I should have been a bit more specific. How do you tell the UltraWebGrid to actually "save" the changes? I know I can code up a "submit" button to save the changes, but I thought I could somehow do it "code" less??? How do I turn on a "save" button?
(And as a side note: How do I also get it to show a "delete" (row) button? "Codeless" I mean...)
I tried this advice from the help info:
Visual Studio's Properties Window
Now that you have set the DataKeyField property on the WebGrid control, any updates, insertions, or deletions should be resolved to the back end (assuming the appropriate permissions on the database are also in place).
But, the "DefaultKeyField" combo doens't give me any choices. I manuuly typed my key field and it still doesn't automatically update the database.
In two-way databinding (automaticallly updating the database), you will typically also need to have BaseTableName defined as well. For example:
<igtbl:UltraGridBand DataKeyField="CustomerID" BaseTableName="Customers">
Also, if you are using AccessDataSource, SqlDataSuorce, etc, make sure you generate the CRUD commands in design time by clicking the Advanced button and the selecting "Generate CRUD..."
Here is more info on 2-way databinding:
Did you know that the grid supports automatic data updating through the datasource control? The days of complicated event handlers dealing with DataSets accepting and rejecting changes are over!! Let's take a SqlDataSource for an example of how to use this feature.
When you create the datasource be sure to click on the "advanced" when building the select statement. You'll see a checkbox for "generate insert, update and delete". Checking that box will enable the datasource to perform all of the 'crud' operations on your table. The grid will automatically update the data, but first a 'postback' must occur. I put a postback in quotes because it can be the traditional full page, or it can be an asynchronous AJAX style postback. If you want the database to be updated with each row modification, you can add a server-side "RowUpdate" event handler. Enabling the AJAX functionality of the grid (click the "Enable AJAX" checkbox in the smart tag at design-time, or set grid.DisplayLayout.LoadOnDemand=Xml) will make the updaterow happen asynchronously, making the entire update process transparent to the end user. If you can't get updating working, check to be sure you set the grid's DataKeyField and BaseTableName properties (Yes, I'm speaking from experience).
I am unable to get the BaseTableName to "stick" in the Designer for the Band Properties. As soon as I Save it and then go back in, it is gone.
I am under the "Edit Data Structure" -> "Bands and Columns" and I have the (only) Band selected. I have also tried prefixing the table name with "dbo." it still won't take it.
Yep, I understand (and know that is general forum ettiquite). I just created a new thread because this one ventured off topic. :)
But, we keep using it...lol
shaynejud said:The mystery is why the adds dont "save"... the rows get added visually and I populate the data (with the appropraite data), but when I do the post back the new rows just disappear.
Generally speaking, it's helpful to folks like me if there's one thread per question, and vice versa, so I'll respond over there.
Fair enough and that explains why my Updates and Deletes work without that property set.
The mystery is why the adds dont "save"... the rows get added visually and I populate the data (with the appropraite data), but when I do the post back the new rows just disappear.
OK, now I am more than a little confused. The designer's description of the .BaseTableName property is "The name of the table in the data store." This would make sense to me if you were binding your grid to a multi-table DataSet. But you are binding a single-band grid to a SqlDataSource that returns a single table. When I'm doing that, I never specify a .BaseTableName.
I don't know why your .BaseTableName is being dropped, but it could be because it is not appropriate in that context.
Actaully, I did that first thing this morning, you guys are just usually quicker. :)