Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Editing Rows in DetailsView with ModalPopupExtender

Reply
Thread Tools

Editing Rows in DetailsView with ModalPopupExtender

 
 
headros headros is offline
Junior Member
Join Date: Jan 2010
Posts: 1
 
      01-26-2010
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>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DetailsView Editing and Reading oldValues newValues problem rahulsurya ASP .Net 0 12-12-2007 05:23 PM
Reusing same DetailsView for both Inserting and Editing David Ching ASP .Net 0 08-29-2007 09:17 PM
Problems with Walkthrough: Editing and Inserting Data in Web Pages with the DetailsView Web Server Control" tom c ASP .Net 0 09-19-2006 10:11 PM
Missing Enable Editing checkbox in GridView and DetailsView K B ASP .Net 1 04-19-2006 06:54 PM
DetailsView - Changing to Insert Mode (Not By Using the Insert Button In the DetailsView Control) Feege ASP .Net Web Controls 0 12-20-2005 12:28 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57