2 Replies - 5831 Views - Last Post: 02 December 2010 - 06:26 PM

#1 Angate   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 28
  • Joined: 05-March 09

grid view won't exit update mode

Posted 02 December 2010 - 03:15 PM

I have a grid view in an update panel, similar to the ajax popup menu example in the ajax sample site. There are a few issues I am having with it that I believe can be traced to my use of a LINQ data source rather than an object data source, like in the example.

The issue is that the grid won't exit edit mode after the "Update" is clicked in the popup menu. Also, to have the update actually occur, I had to write the code in the LINQDataSource_Updating event, though I was lead to believe the update would happen automatically.

here is the code from the aspx page:

            <asp:UpdatePanel ID="haveToOfferUpdatePanel" runat="server" UpdateMode="Conditional">

                <ContentTemplate>

                    <asp:LinqDataSource ID="haveToOfferLinqDataSource" runat="server" TableName="haveToOfferTables"
                        ContextTypeName="LINQClassDataContext" EnableUpdate="True" 
                        EnableInsert="True" EnableDelete="True" EntityTypeName="String">
                    </asp:LinqDataSource>

                    <asp:GridView ID="haveToOfferGridView" runat="server"
                        DataKeyNames="skillID" DataSourceID="haveToOfferLinqDataSource" ShowHeader="False"
                        Width="100%" GridLines="None" AutoGenerateColumns="False" 
                        EnableModelValidation="False" EnableViewState="False">
                        <Columns>
                             <asp:TemplateField>
                                <HeaderTemplate>
                                    
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:Panel CssClass="popupMenu" ID="PopupMenu" runat="server">
                                        <div style="border: 1px outset white; padding: 2px;">
                                            <div>
                                                <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit" Text="Edit" /></div>
                                            <div>
                                                <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Delete" Text="Delete" /></div>
                                            <div>
                                                <asp:LinkButton ID="searchLinkButton" runat="server" CommandName="Search" Text="Search"></asp:LinkButton></div>
                                        </div>
                                    </asp:Panel>
                                    <asp:Panel ID="Panel9" runat="server">
                                        <ul><li>
                                            <h3>
                                                <asp:Label Font-Bold="true" ID="Label1" runat="server" Text='<%# HttpUtility.HtmlEncode(Convert.ToString(Eval("skillName"))) %>' /></h3>
                                            <p>
                                                <asp:Label ID="Label4" runat="server" Text='<%# HttpUtility.HtmlEncode(Convert.ToString(Eval("description"))) %>' /></p>
                                        </li></ul>
                                    </asp:Panel>
                                    <ajax:HoverMenuExtender ID="hme2" runat="Server" HoverCssClass="popupHover"
                                        PopupControlID="PopupMenu" PopupPosition="Left" TargetControlID="Panel9" PopDelay="25" />
                                </ItemTemplate>

                                <EditItemTemplate>

                                    <asp:Panel ID="Panel9" runat="server" Width="80%">
                                        <ul>
                                            <li>
                                                <h3>
                                                    <asp:Label Font-Bold="true" ID="Label1" runat="server" Text='<%# HttpUtility.HtmlEncode(Convert.ToString(Eval("skillName"))) %>' /></h3>
                                                <p>
                                                    <asp:TextBox ID="updateDescriptionTextBox" runat="server" Text='<%# Bind("description") %>'
                                                        Width="150" /></p>
                                            </li>
                                        </ul>
                                    </asp:Panel>

                                    <ajax:HoverMenuExtender ID="hme1" runat="Server" TargetControlID="Panel9"
                                        PopupControlID="PopupMenu" HoverCssClass="popupHover" PopupPosition="Left" />

                                    <asp:Panel ID="PopupMenu" runat="server" CssClass="popupMenu" Width="80">
                                        <div style="border: 1px outset white">
                                            <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Update" CausesValidation="false" Text="Update" />
                                            <br />
                                            <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                                                Text="Cancel" />
                                        </div>
                                    </asp:Panel>
                                </EditItemTemplate>

                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
               </ContentTemplate>
        </asp:UpdatePanel>


And the code behind:

    Protected Sub haveToOfferLinqDataSource_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceSelectEventArgs) Handles haveToOfferLinqDataSource.Selecting

        If currentProfileUserId = Guid.Empty Then
            Dim userNameString As String = User.Identity.Name
            currentProfileUserId = CType(aspnetdb.getUserIDByUserName(userNameString), Guid)
        End If


        If Not currentProfileUserId = Guid.Empty Then

            e.Result = repo.loadHaveToOfferByUserID(currentProfileUserId)

        Else
            e.Cancel = True
        End If

    End Sub

    Protected Sub haveToOfferLinqDataSource_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceUpdateEventArgs) Handles haveToOfferLinqDataSource.Updating

        Dim newObject As haveToOfferTable = DirectCast(e.NewObject, haveToOfferTable)
        Dim skillIDInteger As Integer = newObject.skillID
        Dim descriptionString As String = newObject.description
        repo.updateUserHaveToOffer(currentProfileUserId, skillIDInteger, descriptionString)

    End Sub


Any Ideas on how to have the grid and data source handle the update the automatically as they are supposed to?

Is This A Good Question/Topic? 0
  • +

Replies To: grid view won't exit update mode

#2 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: grid view won't exit update mode

Posted 02 December 2010 - 06:17 PM

set the gridview EditIndex to -1 and that'll take it out of edit mode. Probably want it in the gridview's OnUpdated event, or possibly the linqdatasource's, if it has one, can't remember off the top of my head

This post has been edited by Nakor: 02 December 2010 - 06:28 PM

Was This Post Helpful? 0
  • +
  • -

#3 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: grid view won't exit update mode

Posted 02 December 2010 - 06:26 PM

if you don't have the onupdating event for the linqdatasource do you get an error or does nothing happen?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1