When adding a row using the WebDataGrid it only sends through parameters that are columns in the grid. The problem i have is when I add a row I need an additional insert parameter that is stored in another control on the page (i.e. dropdownlist) or a session object. On the edit I can just include that column on the webdatagrid, which is not ideal but it works. When adding a row I need to default it to the ddl or session value. Your help is appreciated.
Hi,
I can only think of a crazy way to do it. Include the info in another columns insert parameter and then parse it out on the server side in the rowadding event.
Ed
Sorry it took me so long to answer. That solution would help if I could get the value into any other column. My question is how would I do that?
With an regular asp.net datagrid I would create an object with empty and/or default values then add that object to the datasource then bind it to the datagrid with that row as the editing index.
With the Infragisitcs WebDataGrid there is no need to create that "empty" object when using AddingRow. There is already an empty row. When the new row is submitted a function that has the exact number of parameters as columns is needed.
For example,say you have a grid with 3 columns (ID,Name,CategoryID) and your Object Datasource looks like the following:
<asp:ObjectDataSource ID="ods" runat="server" SelectMethod="SelectObject" UpdateMethod="UpdateObject" InsertMehod="InsertObject" TypeName="LIB.DataAccess.DAL"/>
In order to insert you would need a method that looks like:
InsertMethod(int ID,string Name,int CategoryID) {....insert method code here}
Say my page also has one dropdownlist at the top of the page for an OwnerID. How do I pass that OwnerID onto my method?
I need an insert method that looks like:
InsertMethod(int ID,string Name,int CategoryID,int OwnerID) {....insert method code here}
Finally I found the answer.
{
e.Values[
"OwnerID"] = Session["OwnerID"];
OR
e.Values["OwnerID"] = ddlOwner.SelectedValue;
}
The Javascript approach would be used if you had external textboxes where you enter the data and then you would call the JS to do the actual inserting into the datasource/grid. That's not going to help you here since you want the add row in the grid.
Yes. I'm using the empty add row.
In my workaround I just got rid of the AddingRow altogether. I create an empty object with the value that I need. So I always have an empty row at the bottom with the value I need. The ID column is set to -1 so I know when to insert and when to update.
It's not very elegant and I dislike having that empty row at the bottom all the time but it works. Can you show me the javascript approach you are talking about?
I would really prefer a solution that uses the <ig:RowAdding/> feature of the grid but I'll use whatever works.
Here is my stripped down workaround code:
<asp:ObjectDataSource ID="ods" SelectMethod="SelectObject" UpdateMethod="UpdateObject" InsertMethod="InsertObject" TypeName="Namespace">
public List<ObjectName> SelectObject(int OwnerID)
{List<Objectname> lst = new List<ObjectName>();
lst=...code that returns a list of objects based on the OwnerID
ObjectName o = new ObjectName();
o.ID=-1;
o.OwnerID=OwnerID;
lst.Add(o);
return lst;
public void UpdateObject(int ID,string Name,int OwnerID)
if (ID==-1)
{...insert code}
else
{...update code}
I was assuming that you were doing the add row through Javascript. How are you doing the add row, through an empty add row in the grid? What causes the postback to actuall add the row?