I have 3 columns in my table: ProductId, CityName, ProductName. I did the following steps:
1. Add new webgrid to my page2. From ultrawebgrid's design view, create a new SQLDataSource and pick Advanced - generate CRUD3. Make hidden attribute TRUE for ProductId and CityName4. Make sure DataKeyField is set to ProductId5. Allow adds/updates
Inserts and updates all work fine except I want to add a default value for CityName from my code when adding new rows. Currently, it adds NULLs for CityName when adding rows. I have changed my InsertCommand in my TestPage.aspx.vb's PageLoad event as follows:
SqlDataSource.InsertCommand = "INSERT INTO Products ([CityName], [ProductName]) VALUES ('" & SessionCityVar & "', @ProductName)"
Am I missing something here? Strange thing is when I change the InsertCommand code in the aspx page by hardcoding a cityname value, it uses that value when doing inserts. When I change the insertcommand in codebehind, it doesn't work.
That worked!! Thanks.
check the order of events. the aspx is probably overring your codebehind depending on where you are setting the values.
Try setting the values in the InitializeRow event. I am guessing here I dont know the events off hand
UltraWebGrid1.Bands(0).Columns(0).DefaultValue = "Click Me"