Solved

inner gridview with ascx - database does not update

Posted on 2011-03-19
1
902 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
ID: 35176261
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 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