Editing Rows in DetailsView with ModalPopupExtender

Discussion in '.NET' started by headros, Jan 26, 2010.

  1. headros

    headros

    Joined:
    Jan 26, 2010
    Messages:
    1
    I have a GridView in which I'm moving the DetailsView (which is bound to a SqlDataSource) to the ModalPopupExtender for Updating.

    I cannot figure out how to get the Update function to work properly. My method to get the the key and control values into the SqlDataSource UpdateParameters is not working. Can anyone give me some pointers? I cant find anything on the web for Updating with SqlDataSource. Thank you



    I am getting this error

    Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index



    Line 70: String entryKey = values[0].ToString();



    Code:
     protected void BtnEditDetails_Click(object sender, ImageClickEventArgs e)
        {
            //  get the gridviewrow from the sender so we can get the datakey we need
            ImageButton btnEdit = sender as ImageButton;
            GridViewRow row = (GridViewRow)btnEdit.NamingContainer;
    
            //  extract the qreid from the row whose details button originated the postback.
            //  grab the qreid and send it to the qre edit details sqldatasource
            //  rebind the detailview
            this.SqlDataSource5.SelectParameters.Clear();
            this.SqlDataSource5.SelectParameters.Add("qreID", Convert.ToString(this.gvEntry.DataKeys[row.RowIndex].Value));
            this.dvEntryDetail.DataSource = this.SqlDataSource5;
            this.dvEntryDetail.DataBind();
    
            //  update the contents in the detail panel
            this.updPnlEntryDetail.Update();
            //  show the modal popup
            this.mdlPopup.Show();
        }
    
    
    public void BtnUpdateDetails_Click(object sender, ImageClickEventArgs e)
        {
    
            // Create a dictionary that contains the key fields and values using
            // the AllValues method of the DataKey object contained in the  DataKey 
            // property.
            IOrderedDictionary keyList = dvEntryDetail.DataKey.Values;
    
            //object[] test;
            //ArrayList arrlstTemp = ArrayList.Adapter(test);
    
            // Get the ArrayList objects that represent the key fields and values.
    
            ArrayList keys = new ArrayList (keyList.Keys);
            ArrayList values = new ArrayList (keyList.Values);
    
            Console.WriteLine(keys);
           
            // Get the key field and value for the current record. 
            String keyField = keys[0].ToString();
            String keyValue = values[0].ToString();
    
            // Write values to log
            LogUpdate(keyField, keyValue);
    
            SqlDataSource5.UpdateParameters.Add("keyField", "keyValue");
    
            // Find DetailsView control    ((TextBox)DetailsView1.FindControl("tbxProduct_name")).Text;
            SqlDataSource5.Update();
            gvEntry.DataBind();
    
    
    
    
    
        }
    
    
    .aspx

    Code:
         <asp:GridView width="100%" GridLines="None" CssClass="gridview" AutoGenerateColumns="false"
            DataSourceID="SqlDataSource6" ID="gvCounts" runat="server" ShowHeader="False">
              <RowStyle VerticalAlign="Middle" HorizontalAlign="Left" />
             <Columns>
            <asp:TemplateField>
              <ItemTemplate>
            
    ...
    
    
    <div class="gridview_full_row" style="width:25%"><asp:ImageButton ID="btnEditRefills" runat="server" SkinID="accept" ToolTip="Click to Cancel this refill count edit" /> <asp:ImageButton ID="ImageButton1" runat="server" SkinID="delete" CommandName="Cancel" ToolTip="Click to Cancel this refill count edit" /> 
            </div> 
            </div>
            </EditItemTemplate>
            </asp:TemplateField>
            </Columns>
            </asp:GridView> 
    Code:
    
    <asp:Button ID="btnShowPopup" runat="server" Style="display: none" />
            <cc1:ModalPopupExtender ID="mdlPopup" runat="server" TargetControlID="btnShowPopup"
                PopupControlID="pnlPopup" CancelControlID="btnClose" BackgroundCssClass="modalBackground" />
            <asp:Panel ID="pnlPopup" runat="server" Width="500px" Style="display: none">
                 <div align="left" class="modalPopupHeader" style="height:20px">
                 &nbsp;&nbsp;<%= Session["qreStoreName"]%> | Edit Entry </div>
                <asp:UpdatePanel ID="updPnlEntryDetail" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                    <asp:DetailsView ID="dvEntryDetail" onitemupdated="EntryDetailView_ItemUpdated" 
    AutoGenerateRows="false" runat="server" DefaultMode="Edit"
                            Width="600px" GridLines="None" CssClass="modalPopup" DataKeyNames="qreID">
                           <Fields>
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <contenttemplate>
    
    ...
    
    
                                          </contenttemplate>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Fields>
                        </asp:DetailsView>
                     </ContentTemplate>
                </asp:UpdatePanel>
    

    Code:
    
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Personal %>"
            SelectCommand="SELECT   * FROM Reports
    WHERE        (Reports.qreStoreName = @qreStoreName) AND (Reports.qreTodayDate = @qreTodayDate)
    ORDER BY Reports.qreTodayDate DESC" DeleteCommand="DELETE FROM [Reports] WHERE [qreID] = @qreID" >
            <SelectParameters>
                <asp:QueryStringParameter QueryStringField="date" Type="String" Name="qreTodayDate" />
                <asp:SessionParameter Name="qreStoreName" SessionField="qreStoreName" Type="String" />
            </SelectParameters>
            <DeleteParameters>
                <asp:Parameter Name="qreID" Type="Int32" />
            </DeleteParameters>
        </asp:SqlDataSource>
    
    
    <asp:SqlDataSource ID="SqlDataSource5" ConflictDetection="OverwriteChanges" OldValuesParameterFormatString="original_{0}" runat="server" SelectCommand="select * from Reports where qreID=@qreID" UpdateCommand="UPDATE [Reports] 
    SET [qreRefill] = @qreRefill,
     WHERE [qreID] = @qreID"
                SelectCommandType="Text" CancelSelectOnNullParameter="true" ConnectionString="<%$ ConnectionStrings:Personal %>" >
                   <UpdateParameters>
                <asp:Parameter Name="qreID" Type="Int32" />
                <asp:Parameter Name="qreRefill" Type="String" />
                </UpdateParameters>
                </asp:SqlDataSource>
    
    headros, Jan 26, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. K B
    Replies:
    1
    Views:
    3,510
    Craig Deelsnyder
    Apr 19, 2006
  2. tom c
    Replies:
    0
    Views:
    456
    tom c
    Sep 19, 2006
  3. David Ching
    Replies:
    0
    Views:
    382
    David Ching
    Aug 29, 2007
  4. rahulsurya
    Replies:
    0
    Views:
    503
    rahulsurya
    Dec 12, 2007
  5. Feege
    Replies:
    0
    Views:
    451
    Feege
    Dec 20, 2005
Loading...

Share This Page