Solved

inner gridview with ascx - database does not update

Posted on 2011-03-19
1
900 Views
Last Modified: 2012-08-14
I have an inner gridview with an ascx file.  When I update the row of the inner gridview the field in the ascx file is null on the database.  How can I get the stored procedure paramenter to recognize the ascx field? Below are the gridview and the ascx file.

  <asp:GridView ID="ParentGrid" runat="server" AutoGenerateColumns="False" DataSourceID="Names" ShowHeader="False">
         <Columns>
            <asp:TemplateField Visible="False">
               <ItemTemplate>
                    <asp:Label ID="Key" runat="server" Text='<%# Bind("Key") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                  <asp:TextBox ID="TB1" runat="server" Text='<%# Bind("Key") %>'></asp:TextBox>
                 </EditItemTemplate>
               </asp:TemplateField>
                                             
                    <asp:TemplateField>
                        <ItemTemplate>
                      <asp:Label ID="Lab10" runat="server" Text='<%# Bind("name") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                     <asp:Label ID="Lab10" runat="server" Text='<%# Bind("name") %>' ></asp:Label>
                             </EditItemTemplate>
                    </asp:TemplateField>
           
                    <asp:TemplateField>
                        <ItemTemplate>
       <asp:GridView ID="DetailGrid" runat="server" DataSourceID="getData" AutoGenerateColumns="False" DataKeyNames="Keys">
                <Columns>
                    <asp:TemplateField ShowHeader="False">
                        <EditItemTemplate>
  <asp:Button ID="Button1" runat="server" CausesValidation="True" CommandName="Update" Text="Save" />
 &nbsp;<asp:Button ID="Button2" runat="server" CausesValidation="False" CommandName="Cancel"  />
                        </EditItemTemplate>
                        <ItemTemplate>
    <asp:Button ID="Button1" runat="server" CausesValidation="False" CommandName="Edit"  />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="eventTeamHotelKey" Visible="False">
                        <EditItemTemplate>
                   <asp:TextBox ID="TxtB1" runat="server"  Text='<%# Bind("Key") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                  <asp:Label ID="Label1" runat="server" Text='<%# Bind("Key") %>'></asp:Label>
                        </ItemTemplate>
                   </asp:TemplateField>
                  <asp:TemplateField HeaderText=" Number" >
                   <EditItemTemplate>
          <asp:Label ID="Label1" runat="server" Text='<%# Eval("number") %>'  ></asp:Label>
                           
                        </EditItemTemplate>
                        <ItemTemplate>
     sp:Label ID="Label2" runat="server" Text='<%# Bind("number") %>'></asp:Label>
                         </ItemTemplate>
                          </asp:TemplateField>
                    <asp:TemplateField HeaderText="Name">
                        <EditItemTemplate>
      <asp:Label ID="Label2" runat="server" Text='<%# Eval("Name") %>' ></asp:Label>
                        </EditItemTemplate>
                        <ItemTemplate>
        <asp:Label ID="Label3" runat="server" Text='<%# Bind("Name") %>' ></asp:Label>
                        </ItemTemplate>
             </asp:TemplateField>
                    <asp:TemplateField HeaderText=" First Name">
                        <EditItemTemplate>
         <asp:TextBox ID="FirstName" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
           <asp:Label ID="Label4" runat="server" Text='<%# Bind("FirstName") %>' ></asp:Label>
                        </ItemTemplate>
     </asp:TemplateField>
                    <asp:TemplateField HeaderText="Type" >
                          <ItemTemplate>
            <asp:DropDownList ID="Type" runat="server" DataSourceID="Type" AppendDataBoundItems="true"
                DataTextField="nam" DataValueField="Type"  Enabled="false" SelectedValue='<%# Bind("Type")%>'>
        <asp:ListItem Value="-1" Selected="True">Type Not Selected</asp:ListItem>
                 </asp:DropDownList>      
                               
                        </ItemTemplate>
                        <EditItemTemplate>
           <asp:DropDownList ID="Type" runat="server" DataSourceID="Type" AppendDataBoundItems="true"
                DataTextField="nam" DataValueField="Type" SelectedValue='<%# Bind("Type")%>'>
            <asp:ListItem Value="-1" Selected="True">Type</asp:ListItem>
            </asp:DropDownList>      
                                                         
                        </EditItemTemplate>
                     
</asp:TemplateField>
                    <asp:TemplateField HeaderText="Month" >
                        <EditItemTemplate>
                             
                            <CCMON:ccmonth id="Month1" runat="server" />  
                         
                        </EditItemTemplate>
                        <ItemTemplate>
                 
                              <CCMON:ccmonth id="Month1" runat="server"/>
                        </ItemTemplate>
   </asp:TemplateField>
                </Columns>
         
            </asp:GridView>

            <asp:SqlDataSource ID="getData" runat="server"
                ConnectionString="<%$ ConnectionStrings %>"
           
                 updateCommand="sp_update_detail"  UpdateCommandType="StoredProcedure">
                </SelectParameters>      
                     <UpdateParameters>
                    <asp:Parameter Name="Key" Type="Int32" />
                    <asp:Parameter Name="number" Type="Int32" />
                    <asp:Parameter Name="FirstName" Type="String" />
                    <asp:Parameter Name="Type" Type="String" />
                    <asp:Parameter Name="Month"  Type="Int32"   />
                </UpdateParameters>
            </asp:SqlDataSource>
                          </ItemTemplate>
                      </asp:TemplateField>
                </Columns>
     
            </asp:GridView>

Monthcalc.ascx

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="MonthCalc.ascx.vb" Inherits="MonthCalc" %>
<asp:DropDownList ID="Month" runat="server" SelectedValue='<%# Bind("Month")%>' >
</asp:DropDownList>
<asp:RequiredFieldValidator ControlToValidate="Month" ID="MonthRFV" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>  


Partial Class MonthCalc
    Inherits System.Web.UI.UserControl

    Protected Sub Month_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Month.Init
        Dim intMonth As Integer
        Dim intStart As Integer = DateTime.Now.Year
        Dim intEnd As Integer = DateTime.Now.Year + 10

        For intMonth = 1 To 12
            Month.Items.Add(intMonth.ToString())
        Next
        Month.Items.Add(New ListItem("Month", "-1"))

    End Sub
End Class
0
Comment
Question by:kw66722
1 Comment
 
LVL 1

Accepted Solution

by:
kw66722 earned 0 total points
Comment Utility
I created a hidden field for the ascx control. Saved the selected value to the hidden field and changed from a parmater to a controlParameter.  I was able to save the information doing that.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now