Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6859393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:16:39+00:00 2026-05-27T02:16:39+00:00

Background I have a GridView that builds a table using an ObjectDataSource . This

  • 0

Background

I have a GridView that builds a table using an ObjectDataSource. This source uses web services for both the select and update segments. Under the edit section, when clicked, has a DropDownList appear for the two columns that need to be editable. The DropDownLists both use separate ObjectDataSources storing WebServices that obtain the values meant to be stored in this DropDownList.

Currently working

At the moment, all of the above works. When I load the page, the table comes up with the proper data. When I click on the edit button, the two DropDownLists come up with the proper data stored in them from the WebService.

The Problem

When I select an option to update the DB or when I select cancel, the page throws an error and fails. I am not entirely sure why this happens, other than that it has to do with the binding not being handled correctly. I would like to know how to bind the values obtained from the DropDownList to be used when updating the database?

Below you will find what i have tried so far:

<asp:GridView ID="GridViewHolder" 
                          runat="server" 
                          AllowPaging="True" 
                          AutoGenerateColumns="False" 
                          BackColor="Transparent" 
                          BorderColor="#999999" 
                          BorderStyle="Ridge" 
                          BorderWidth="3px" 
                          CellPadding="4" 
                          CellSpacing="2" 
                          DataSourceID="MachineDataSet" 
                          ForeColor="Black" 
                          HeaderStyle-HorizontalAlign="Center" 
                          HorizontalAlign="Center"  
                          RowStyle-HorizontalAlign="Center" Width="574px"
                          OnRowUpdating="GridViewHolder_Updating"
                          OnRowCancelingEdit="GridViewHolder_Canceling"
                          OnRowUpdated="GridViewHolder_Updated"
                          OnRowEditing="GridViewHolder_Editing">
                <RowStyle BackColor="Transparent" HorizontalAlign="Center" />
                <Columns>
                    <asp:BoundField DataField="ID" 
                                    HeaderText="ID" 
                                    SortExpression="ID" 
                                    Visible="False" />
                    <asp:BoundField DataField="SiteName" 
                                    HeaderText="Site Name" 
                                    SortExpression="SiteName"
                                    ReadOnly="true" />
                    <asp:BoundField DataField="Name" 
                                    HeaderText="Machine Name" 
                                    ReadOnly="true" 
                                    SortExpression="Name" />
                    <asp:TemplateField HeaderText="Machine Type" SortExpression="MachineType">
                        <EditItemTemplate>
                            <asp:ObjectDataSource ID="GetMachineType" 
                                                  runat="server" 
                                                  SelectMethod="GetMachineTypeList" 
                                                  TypeName="Datamart.UI.Reporting.Web.FilteredReportInputsSvc.FilteredReportInputsService">
                                <SelectParameters>
                                    <asp:Parameter Name="siteid" Type="String" />
                                </SelectParameters>
                            </asp:ObjectDataSource>
                            <asp:DropDownList ID="MachineTypeDropDown" 
                                              runat="server" 
                                              AppendDataBoundItems="True" 
                                              DataSourceID="GetMachineType" 
                                              DataTextField="Name" 
                                              DataValueField="ID"                                               
                                              Height="21px" 
                                              Width="217px">
                                <asp:ListItem Enabled="true" 
                                              Text="Select a Machine Type.">
                                </asp:ListItem>
                            </asp:DropDownList>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" 
                                       runat="server" 
                                       Text='<%# Bind("MachineType") %>'>
                            </asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Machine Model" SortExpression="MachineModel">
                        <EditItemTemplate>
                            <asp:ObjectDataSource ID="GetMachineModel" 
                                                  runat="server" 
                                                  SelectMethod="GetMachineModelList" 
                                                  TypeName="Datamart.UI.Reporting.Web.FilteredReportInputsSvc.FilteredReportInputsService">
                                <SelectParameters>
                                    <asp:Parameter Name="siteid" Type="String" />
                                </SelectParameters>
                            </asp:ObjectDataSource>
                            <asp:DropDownList ID="MachineModelDropDown" 
                                              runat="server" 
                                              AppendDataBoundItems="True" 
                                              DataSourceID="GetMachineModel" 
                                              DataTextField="Name" 
                                              DataValueField="ID"                                               
                                              Height="21px" 
                                              Width="217px">
                                <asp:ListItem Enabled="true" 
                                              Text="Select a Machine Model."
                                              Value="NULL">
                                </asp:ListItem>
                            </asp:DropDownList>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label2" 
                                       runat="server" 
                                       Text='<%# Bind("MachineModel") %>'>
                            </asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:CommandField ButtonType="Button" ShowEditButton="True" />
                </Columns>
                <FooterStyle BackColor="Transparent" />
                <PagerStyle BackColor="Transparent" 
                            ForeColor="Black" 
                            HorizontalAlign="Left" />
                <SelectedRowStyle BackColor="Transparent" 
                                  Font-Bold="True" 
                                  ForeColor="White" />
                <HeaderStyle BackColor="Black" 
                             Font-Bold="True" 
                             ForeColor="White" 
                             HorizontalAlign="Center" />
         </asp:GridView>

Where the problem seems to lie, is in this area below:

<asp:TemplateField HeaderText="Machine Type" 
    SortExpression="MachineType">
    <EditItemTemplate>
        <asp:ObjectDataSource ID="GetMachineType" 
            runat="server" 
            SelectMethod="GetMachineTypeList" 
            TypeName="Datamart.UI.Reporting.Web.FilteredReportInputsSvc.FilteredReportInputsService">
            <SelectParameters>
                <asp:Parameter Name="siteid" Type="String" />
            </SelectParameters>
        </asp:ObjectDataSource>
        <asp:DropDownList ID="MachineTypeDropDown" 
            runat="server" 
            DataSourceID="GetMachineType"
            DataTextField="Name"
            DataValueField="ID"                                               
            Height="21px" 
            Width="217px"
            AppendDataBoundItems="true">
            <asp:ListItem Enabled="true"
                Selected="True"
                Text="Select a Machine Type.">                                 
            </asp:ListItem>
        </asp:DropDownList>
    </EditItemTemplate>
    <ItemTemplate>
        <asp:Label ID="Label1" 
            runat="server" 
            Text='<%# Bind("MachineType") %>'>
        </asp:Label>
    </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Machine Model" 
    SortExpression="MachineModel">
    <EditItemTemplate>
        <asp:ObjectDataSource ID="GetMachineModel" 
            runat="server" 
            SelectMethod="GetMachineModelList" 
            <asp:TemplateField HeaderText="Machine Type" SortExpression="MachineType">
                    <EditItemTemplate>
                        <asp:ObjectDataSource ID="GetMachineType" 
                                              runat="server" 
                                              SelectMethod="GetMachineTypeList" 
                                              TypeName="Datamart.UI.Reporting.Web.FilteredReportInputsSvc.FilteredReportInputsService">
                            <SelectParameters>
                                <asp:Parameter Name="siteid" Type="String" />
                            </SelectParameters>
                        </asp:ObjectDataSource>
                        <asp:DropDownList ID="MachineTypeDropDown" 
                                          runat="server" 
                                          AppendDataBoundItems="True" 
                                          DataSourceID="GetMachineType" 
                                          DataTextField="Name" 
                                          DataValueField="ID"                                               
                                          Height="21px" 
                                          Width="217px">
                            <asp:ListItem Enabled="true" 
                                          Text="Select a Machine Type.">
                            </asp:ListItem>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" 
                                   runat="server" 
                                   Text='<%# Bind("MachineType") %>'>
                        </asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Machine Model" SortExpression="MachineModel">
                    <EditItemTemplate>
                        <asp:ObjectDataSource ID="GetMachineModel" 
                                              runat="server" 
                                              SelectMethod="GetMachineModelList" 


TypeName="Datamart.UI.Reporting.Web.FilteredReportInputsSvc.FilteredReportInputsService">
                            <SelectParameters>
                                <asp:Parameter Name="siteid" Type="String" />
                            </SelectParameters>
                        </asp:ObjectDataSource>
                        <asp:DropDownList ID="MachineModelDropDown" 
                                          runat="server" 
                                          AppendDataBoundItems="True" 
                                          DataSourceID="GetMachineModel" 
                                          DataTextField="Name" 
                                          DataValueField="ID"                                               
                                          Height="21px" 
                                          Width="217px">
                            <asp:ListItem Enabled="true" 
                                          Text="Select a Machine Model."
                                          Value="NULL">
                            </asp:ListItem>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" 
                                   runat="server" 
                                   Text='<%# Bind("MachineModel") %>'>
                        </asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>

Updated for bounty

My overall problem is: using the gridview, I am unable to get my edit, update, cancel buttons to work. So what I would like to also know since I am throwing a bounty on this is: how can I get these events to work properly using ObjectDataSources?

I already know that the web services work properly, I just do not know how to load the necessary parameters with the right data-values from the table. Any help or suggestions are greatly appreciated.

Error thrown at the moment:

Failed to load viewstate. The control tree into
which viewstate is being loaded must match the
control tree that was used to save viewstate
during the previous request. For example, when
adding controls dynamically, the controls added
during a post-back must match the type and
position of the controls added during the
initial request.

I am unsure as to how to get the update and cancel events to fire correctly, so I have been trying to use the OnRow* event handlers, but none of these work or fire, even when I set up a break point on a method just to see if the event will fire.

Update2

So as requested here is what i have for the code behind dealing with the the events i had thought might fire, (note: i’ve tried this with almost all of the other events). When i would run a debugger attaching the page to an asp.net process and click on the update button, cancel button, or edit button i would expect the page to go to the breakpoint, however this does not happen.

Note: I also know that the code behind is most likely incorrect, but i didn’t want to fix any of that until i knew which event would be the right one that fires for update and cancel buttons.

    protected void GridViewHolder_Updating(object sender, GridViewUpdateEventArgs e) 
{

    int machineid;
    string machineTypeid;
    string machineModelid;

    GridViewRow row = (GridViewRow)GridViewHolder.Rows[e.RowIndex];
    Label id = (Label)row.FindControl("ID");
    DropDownList mType1 = GridViewHolder.Rows[e.RowIndex].FindControl("MachineTypeDropDown") as DropDownList;
    e.NewValues["MachineType"] = mType1.SelectedValue;
    DropDownList mType = (DropDownList)row.FindControl("Machine_Type");
    DropDownList mModel = (DropDownList)row.FindControl("Machine_Model");

    machineid = Convert.ToInt32(id);
    machineTypeid = mType.DataValueField.ToString();
    machineModelid = mModel.DataValueField.ToString();

    inputsService.UpdateMachineTypes(machineid, machineTypeid);
    inputsService.UpdateMachineModels(machineid, machineModelid);

}

protected void GridViewHolder_Updated(object sender, GridViewUpdatedEventArgs e)
{

}

/// <summary>
/// Handles the Click event of the cancel button under edit in the gridview control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewCancelEditEventArgs"/> instance containing the event data.</param>
protected void GridViewHolder_Canceling(object sender, GridViewCancelEditEventArgs e)
{
    //reset the edit index
    GridViewHolder.EditIndex = -1;
    //Bind data to GridViewHolder
    BindData();
}

protected void GridViewHolder_Editing(object sender, GridViewEditEventArgs e)
{

}
#endregion

#region Private Methods

private void BindData()
{
    GridViewHolder.DataSource = Session["MachineTable"];
    GridViewHolder.DataBind();
}

#endregion

Update 3

Okay you will find above the most recent attempt that i have done to try and get the update and cancel buttons to function properly in the gridview.

Any help or suggestions are greatly appreciated.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:16:39+00:00Added an answer on May 27, 2026 at 2:16 am

    One possible solution would be to enable the viewstate to false as so:

    EnableViewState=”false”

    The links below will be of some help.

    http://forums.asp.net/t/1159585.aspx/1

    http://forums.asp.net/t/1295517.aspx/1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataTemplate that I am using for a cell in a gridview.
Background: I have a ListView / GridView with several columns. In some situations, only
Background: I have a kubuntu laptop right now that I can't use wirelessly, i.e.
Background: we have an application that generates reports from HTML (that may or may
Background I have made a Web Service in Visual Studio, and I'm trying to
I have a gridview in an update panel and am using a jQuery dialog
This is a new one I have never seen before. I have a gridview
I have a ListView. When I select a row I want that only one
Background I have a GridView where input in Column1 depends on the input Column2
This is really bugging me. I'm using a GridView and want to format it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.