Editing Rows in DetailsView with ModalPopupExtender

Jan 26, 2010
Reaction score
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();

 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.Add("qreID", Convert.ToString(this.gvEntry.DataKeys[row.RowIndex].Value));
        this.dvEntryDetail.DataSource = this.SqlDataSource5;

        //  update the contents in the detail panel
        //  show the modal popup

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);

        // 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;



     <asp:GridView width="100%" GridLines="None" CssClass="gridview" AutoGenerateColumns="false"
        DataSourceID="SqlDataSource6" ID="gvCounts" runat="server" ShowHeader="False">
          <RowStyle VerticalAlign="Middle" HorizontalAlign="Left" />

<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" /> 

<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">
                <asp:DetailsView ID="dvEntryDetail" onitemupdated="EntryDetailView_ItemUpdated" 
AutoGenerateRows="false" runat="server" DefaultMode="Edit"
                        Width="600px" GridLines="None" CssClass="modalPopup" DataKeyNames="qreID">



<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" >
            <asp:QueryStringParameter QueryStringField="date" Type="String" Name="qreTodayDate" />
            <asp:SessionParameter Name="qreStoreName" SessionField="qreStoreName" Type="String" />
            <asp:Parameter Name="qreID" Type="Int32" />

<asp:SqlDataSource ID="SqlDataSource5" ConflictDetection="OverwriteChanges" OldValuesParameterFormatString="original_{0}" runat="server" SelectCommand="select * from Reports where [email protected]" UpdateCommand="UPDATE [Reports] 
SET [qreRefill] = @qreRefill,
 WHERE [qreID] = @qreID"
            SelectCommandType="Text" CancelSelectOnNullParameter="true" ConnectionString="<%$ ConnectionStrings:Personal %>" >
            <asp:Parameter Name="qreID" Type="Int32" />
            <asp:Parameter Name="qreRefill" Type="String" />


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