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 6380863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:19:21+00:00 2026-05-25T02:19:21+00:00

im having some wierd issue with my GridView. Basically, im trying to run a

  • 0

im having some wierd issue with my GridView. Basically, im trying to run a delete command on a table. The gridview has 3 fields bound to it, ItemId, ItemSummary, and ItemDate.

Now as i recall, during a mode change (say, between Select and Edit) these fields are automatically passed using the syntax @+FieldName (ie. ItemId is passed as @ItemId).

So keeping this in mind i tried the delete statement, but it gave an error saying the parameter was not passed. So i tried the other route, to extract the ItemId programmatically and insert it as a parameter at runtime.

I tried reading from the DataItem bound to to the control, but it kept returning null.

After some more debugging, i found that when the data was initially bound to the control, it correctly created a DataItem, but as soon as the mode was changed the DataItem is now null.

I have been trying to fix this for ages and it just wont work. Here is my code:

<asp:DetailsView FieldHeaderStyle-CssClass="bold" CssClass="marginLeftRightBottom10px center"
                AutoGenerateDeleteButton="true" AutoGenerateEditButton="true" GridLines="Both"
                ID="dvIndividualUpdate" AutoGenerateInsertButton="true" runat="server" AutoGenerateRows="False"
                DataSourceID="sqldsSingleUpdate" OnDataBound="dvIndividualUpdate_DataBound">
                <Fields>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            Update Id:
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:Label Text='<%# Eval("updateId") %>' ID="lblUpdateId" runat="server"></asp:Label>
                        </ItemTemplate>
                        <InsertItemTemplate>
                            <asp:Label Text='Auto Generated' ID="lblUpdateIdInsert" runat="server"></asp:Label>
                        </InsertItemTemplate>
                        <EditItemTemplate>
                            <asp:Label Text='Auto Generated' ID="lblUpdateIdEdit" runat="server"></asp:Label>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            Update Summary:
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:Label Text='<%# Eval("updateSummary") %>' ID="lblUpdateSummary" runat="server"></asp:Label>
                        </ItemTemplate>
                        <InsertItemTemplate>
                            <asp:TextBox CssClass="tbUpdateSummaryInsert" TextMode="MultiLine" Text='<%# Bind("updateSummary") %>'
                                ID="tbUpdateSummary" runat="server"></asp:TextBox>
                        </InsertItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox CssClass="tbUpdateSummaryEdit" TextMode="MultiLine" Text='<%# Bind("updateSummary") %>'
                                ID="tbUpdateSummary" runat="server"></asp:TextBox>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            Update Date:
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:Label Text='<%# Eval("dateOfUpdate") %>' ID="lblDateOfUpdateInsert" runat="server"></asp:Label>
                        </ItemTemplate>
                        <InsertItemTemplate>
                            <asp:Label Text='' ID="lblEditDateOfUpdate" runat="server"></asp:Label>
                        </InsertItemTemplate>
                        <EditItemTemplate>
                            <asp:Label Text='<%# Eval("dateOfUpdate") %>' ID="lblDateOfUpdateEdit" runat="server"></asp:Label>
                        </EditItemTemplate>
                    </asp:TemplateField>
                </Fields>
            </asp:DetailsView>
            <asp:Label ID="lblUpdateErrors" runat="server" Text="" CssClass="block colorRed marginBottom10px center"></asp:Label>

            <asp:SqlDataSource DataSourceMode="DataSet" ID="sqldsSingleUpdate" runat="server"
                ConnectionString="<%$ ConnectionStrings:myDbConnection%>" SelectCommandType="StoredProcedure"
                SelectCommand="dbo.getUpdate" InsertCommand="dbo.createUpdate" InsertCommandType="StoredProcedure"
                OnInserted="sqldsSingleUpdate_Inserted" DeleteCommand="dbo.deleteUpdate" DeleteCommandType="StoredProcedure"
                OnDeleted="sqldsSingleUpdate_Deleted" OnDeleting="sqldsSingleUpdate_Deleting">
                <DeleteParameters>
                    <asp:Parameter Name="updateID" />
                </DeleteParameters>
                <SelectParameters>
                    <asp:ControlParameter Name="updateId" ControlID="gvUpdates" PropertyName="SelectedDataKey.Value" />
                </SelectParameters>
                <InsertParameters>
                    <asp:ControlParameter DbType="Date" ControlID="dvIndividualUpdate$lblEditDateOfUpdate"
                        Name="dateOfUpdate" PropertyName="Text" />
                </InsertParameters>
            </asp:SqlDataSource>

And my related codebehind:

protected void dvIndividualUpdate_DataBound(object sender, EventArgs e)
{
    if (dvIndividualUpdate.CurrentMode == DetailsViewMode.Insert)
    {
        Label lbl = dvIndividualUpdate.FindControl("lblEditDateOfUpdate") as Label;
        lbl.Text = DateTime.Today.ToString("dd-MM-yyyy");
    }
}

protected void sqldsSingleUpdate_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
    if (e.Exception != null)
    {
        Exception ex = e.Exception;
        lblUpdateErrors.Text = "There was a problem creating the update.";
        ErrorSignal.FromCurrentContext().Raise(ex);
        e.ExceptionHandled = true;
        return;
    }
    else
    {
        lblUpdateErrors.Text = "Update created successfully.";
        gvUpdates.DataBind();
    }
}
protected void sqldsSingleUpdate_Deleted(object sender, SqlDataSourceStatusEventArgs e)
{
    if (e.Exception != null)
    {
        Exception ex = e.Exception;
        lblUpdateErrors.Text = "There was a problem deleting the update.";
        ErrorSignal.FromCurrentContext().Raise(ex);
        e.ExceptionHandled = true;
        return;
    }
    else
    {
        lblUpdateErrors.Text = "Update deleted successfully.";
        gvUpdates.DataBind();
    }
}

Thanks a lot

  • 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-25T02:19:22+00:00Added an answer on May 25, 2026 at 2:19 am

    If you add ItemID as a data key to the GridView, the data source control should grab it automatically for the update and delete. Remove the update and delete parameters from the data source, assign the ItemID as a data key, and give that a shot.

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

Sidebar

Related Questions

I am having some weird issue here. I have a database table which has
I'm having some wierd behaviour in my WinForm application coded in c#. in my:
Having some issues with the ... in ObjectiveC. I'm basically wrapping a method and
Hey having some trouble trying to maintain transparency on a png when i create
I’m having some difficulties while trying to consume an unmanaged-code dll from my application
I'm having some weird issues with Xcode, and this is pretty much impossible to
I'm having some weird issues with pytz's .localize() function. Sometimes it wouldn't make adjustments
I'm having some weird trouble with a project on VS2005. I have a few
I'm new to Ruby, so I'm having some trouble understanding this weird exception problem
I'm having the weird problem that after having javascript inject some dom-elements the css-rules

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.