Gridview Update via ObjectDataSource Issue

T

tim.cavins

I have a GridView populated by an ObjectDataSource.

I am having issues passing the parameters to the objectdatasource. I
have verified that the method is being called but none of the
parameters are being populated. Integers are being passed as 0 and
strings are empty regardless of what I changed them to in Edit mode on
the GridView.

My object method to perform the update:

Public Shared Sub Update(ByVal intID As Integer, ByVal intType As
Integer, ByVal intModel As Integer, ByVal intSA As Integer, ByVal
strSer As String, ByVal strPO As String, ByVal strPrj As String, ByVal
strRV As String, ByVal intQty As Integer, ByVal strComment As String)

....
End Sub


Here is my ObjectDataSource:

<asp:ObjectDataSource ID="odsSA" runat="server" SelectMethod="GetSA"
TypeName="App_BL.SA" UpdateMethod="Update">
<SelectParameters>
....
</SelectParameters>
<UpdateParameters>
<asp:FormParameter Name="intID" FormField="hdnSAID" Type="Int32" />
<asp:FormParameter Name="intType" FormField="drpEditSAType"
Type="Int32" />
<asp:FormParameter Name="intModel" FormField="drpEditModel"
Type="Int32" />
<asp:FormParameter Name="intSA" FormField="drpEditSA" Type="Int32" />
<asp:FormParameter Name="strSer" FormField="txtEditSASer"
Type="String" />
<asp:FormParameter Name="strComment" FormField="txtEditSAComment"
Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>

My GridView Edit Template:

<tr>

<td><asp:DropDownList ID="drpEditModel" runat="server" /></td>

<td><asp:DropDownList ID="drpEditSA" runat="server" /></td>

<td><asp:TextBox ID="txtEditSASer" runat="server" Text='<%#
Eval("saser") %>' /></td>

<td><asp:TextBox ID="txtEditPO" runat="server" Text='<%# Eval("saPO")
%>' /></td>

<td><asp:TextBox ID="txtEditPrj" runat="server" Text='<%# Eval("prj")
%>' /></td>

<td><asp:TextBox ID="txtEditRV" runat="server" Text='<%# Eval("RV")
%>' /></td>

<td><asp:TextBox ID="txtEditQty" runat="server" Text='<%# Eval("qty")
%>' /></td>

<td><asp:TextBox ID="txtEditSAComment" runat="server" Text='<%#
Eval("comment") %>' TextMode="MultiLine" Rows="3" Columns="20" /></td>

</tr>

What needs to be done so I can have the values from the GridView
populate my Update method?

If any other info is needed, please let me know.

Tim
 
G

Guest

Hi Tim,
if you want to update your values from grid view you have to use to way
databinding verb. Eval is just one way - it will only populate your gridview
from data source. Try to use Bind instead like
<asp:TextBox ID="txtEditSASer" runat="server" Text='<%#Bind("saser") %>' />

Regards,
Ladislav
 
T

tim.cavins

Ladislav,

I changed the Eval's to Bind for the Text Boxes. I then re-ran my
application and am now getting the following error when I click the
Update link:

ObjectDataSource 'odsSA' could not find a non-generic method 'Update'
that has parameters: intID, intType, intModel, intSA, strSer, strPO,
strPrj, strRV, intQty, strComment, id, then it lists the field names
that have Bind("") in them but does not list my drop down lists.

Any insight on this?

Tim
 
G

Guest

Hi Tim,
I am sorry I didn't notice drop down lists before. Yes, drop down lists are
problem. You have to handle them in different way. You can add handler for
RowUpdating event to your GridView. There you can add selected values from
your drop down lists to NewValues collection.

protected void myGrid_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
{
e.NewValues.Add("intSA", GetSelectedValueFromMyDropDownList());
}

NewValues contains all values bind in your row for updating. I'm not sure if
I'm using right identifier for param. The best way how to check it is to stop
execution in this method and check collection in debugger - then use similar
identifiers like those used in collection for your text boxes.

I have used this technique several times but always with FormView and with
ObjectDataSource using DataObjectTypeName parameter = my update methods were
static with single parameter. I hope this will work but probably you will
have to play little bit with it.

Regards,
Ladislav
 
T

tim.cavins

Ladislav,

I have added my dropdownlists into the RowEditing method. However, I'm
still getting the same non-generic error message when I click the
update button.

It is checking for an Update method that contains the fields I listed
as parameters plus all the TextBoxes that appear in the Edit mode of
the gridview. Why is the objectdatasource adding these and how do I
get around it?

Tim
 
G

Guest

Hi Tim,
you don't have to define parameters for controls which are connected to data
source via Bind method otherwise result set of parameters will contains them
twice. Data source is always prefilled by parameters corresponding to each
Bind call in edit/insert template. Lets try to delete them and leave only
parameters for drop down lists - I am not sure if my previous post will help
you in your case, because you are using different approach to update item
then me. I will have a look at your problem tommorow morning because I have
11:15 PM at the moment and my head is becoming out of order ...

Regards,
Ladislav
 
T

tim.cavins

Ladislav,

Thank you very much. You have been helpful in my learning of the
objectdatasource.

In the time I posted and you posted your previous message, I tried
removing all the Update Parameters and I renamed all the Update
attributes to match the names of the drop down lists and bind values.
ie <%# Bind("prj") %> resulted in an Update attribute of prj etc.

Again, thanks! It is much appreciated.

Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top