文本框无法从代码更新

时间:2016-11-11 06:51:30

标签: c# asp.net bootstrap-modal

当运行代码时,我的文本框没有填写,此代码在我的模态代码中,因此内部有一个更新面板,用户选择ddlid。如果用户选择了一个特定的id,数据库中的一列将被显示并填入txtType,但是当我运行代码时,我放了一个断点,它是成功的,但是在我的网页中,它没有显示结果甚至显示在我的代码中。我的代码有什么问题?

这是我的aspx代码

 <asp:UpdatePanel ID="panel1" runat="server">
         <ContentTemplate>
            <asp:GridView ID="gvModal" runat="server" AutoGenerateColumns="false" DataKeyNames="ID" EmptyDataText="No Records" AllowPaging="true" CellPadding="4" HeaderStyle-BackColor="CornflowerBlue" BorderWidth="2" BorderColor="CornflowerBlue" Width="100%" CssClass="table table-hover"  >
        <Columns>                
            <asp:TemplateField HeaderText ="ID" HeaderStyle-ForeColor="White">
                <ItemTemplate>
                    <asp:Label ID="lblID" runat="server" Text='<%#Bind ("ID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText ="Type" HeaderStyle-Width="20%" ItemStyle-Width="20%" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri" >
                <ItemTemplate>
                    <asp:Label ID="lbltype" runat="server" Text='<%#Bind ("ItemType") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText ="Model" HeaderStyle-Width="30%" ItemStyle-Width="30%" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
                <ItemTemplate>
                    <asp:Label ID="lblModel" runat="server" Text='<%# Bind("ItemModel") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText ="Requested Quantity" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
                <ItemTemplate>
                    <asp:Label ID="lblQuan" runat="server" Text='<%#Bind ("ItemQuantity") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText ="AMS Actual Balance" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
                <ItemTemplate>
                    <asp:Label ID="lblActual" runat="server"></asp:Label>  
                </ItemTemplate>     
            </asp:TemplateField>
            <asp:TemplateField HeaderText ="Incoming Stock" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
                <ItemTemplate>
                    <asp:Label ID="lblIncoming" runat="server"></asp:Label>  
                </ItemTemplate>     
            </asp:TemplateField>
            <asp:TemplateField HeaderText ="AMS Issuable Balance" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
                <ItemTemplate>
                    <asp:Label ID="lblAMs" runat="server"></asp:Label>  
                </ItemTemplate>     
            </asp:TemplateField>
            <asp:TemplateField HeaderText ="Unit" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
                <ItemTemplate>
                    <asp:Label ID="lblUnit" runat="server" Text='<%#Bind ("ItemUnit") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText ="Date Needed" HeaderStyle-Width="15%" ItemStyle-Width="15%" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
                <ItemTemplate>
                    <asp:Label ID="lblDate" runat="server"  Text='<%#Bind ("ItemDate" , "{0:yyyy-MM-dd}") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText ="Description" HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
                <ItemTemplate>
                    <asp:Label ID="lblDesc" runat="server" Text='<%#Bind ("ItemDesc") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText ="Status" ItemStyle-Width="10%" HeaderStyle-Width="10%"  HeaderStyle-ForeColor="White" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
                <ItemTemplate>
                    <asp:Label ID="lblStatus" runat="server" Text='<%#Bind ("ItemStatus") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
             <asp:TemplateField HeaderText ="PO Number" HeaderStyle-ForeColor="White" ItemStyle-Width="120px" ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
                <ItemTemplate>
                    <asp:Label ID="lblPONumber2" runat="server" Text='<%#Bind ("PO_Num") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>     
            <asp:TemplateField HeaderText ="PO Date" HeaderStyle-ForeColor="White"  ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
                <ItemTemplate>
                    <asp:Label ID="lblPODate2" runat="server" Text='<%#Bind ("PO_Date", "{0:yyyy-MM-dd}") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>   
            <asp:TemplateField HeaderText ="Delivery Date" HeaderStyle-ForeColor="White"  ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
                <ItemTemplate>
                    <asp:Label ID="lblDelDate2" runat="server" Text='<%#Bind ("Delivery_Date", "{0:yyyy-MM-dd}") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>        
            <asp:TemplateField HeaderText ="Issuance Date" HeaderStyle-ForeColor="White"  ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
                <ItemTemplate>
                    <asp:Label ID="lblIssDate2" runat="server" Text='<%#Bind ("IssuanceDate", "{0:yyyy-MM-dd}") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>   
            <asp:TemplateField HeaderText ="Issuance Number" HeaderStyle-ForeColor="White"  ItemStyle-Font-Names="Calibri" HeaderStyle-Font-Names="Calibri">
                <ItemTemplate>
                    <asp:Label ID="lblIssNum2" runat="server" Text='<%#Bind ("IssuanceNumber") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>                    
            <asp:TemplateField HeaderText="Last Issuance" ItemStyle-Font-Names="Calibri" HeaderStyle-ForeColor="White" HeaderStyle-BackColor="#336699" ItemStyle-Width="150px">
                <ItemTemplate>
                    <asp:Label ID ="lblIssued" runat="server"></asp:Label>
                </ItemTemplate>                  
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Quantity" HeaderStyle-ForeColor="White" HeaderStyle-BackColor="#336699" ItemStyle-Font-Names="Calibri" ItemStyle-Width="10px">
                <ItemTemplate>
                    <asp:Label ID ="lblQuantity" runat="server"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>    
            <asp:TemplateField HeaderText="Unit" HeaderStyle-ForeColor="White" HeaderStyle-BackColor="#336699" ItemStyle-Font-Names="Calibri" ItemStyle-Width="20px">
                <ItemTemplate>
                    <asp:Label ID ="lblUnits" runat="server"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>      
            <asp:TemplateField HeaderText="Edit" HeaderStyle-ForeColor="White" HeaderStyle-BackColor="#336699" ItemStyle-Font-Names="Calibri" ItemStyle-Width="80px">
                <ItemTemplate>
                    <asp:DropDownList ID="ddlEditModel" CssClass="form-control" runat="server" AutoPostBack="true"></asp:DropDownList>
                </ItemTemplate>
            </asp:TemplateField>

        </Columns>
    </asp:GridView>

             <div class="form-inline">
                    &emsp;<label class="control-label" style="font-family:Calibri">Item ID: </label>&emsp;&emsp;

                    <asp:DropDownList ID="ddlID" runat="server" CssClass="form-control" Width="5%" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlID_SelectedIndexChanged" AutoPostBack="true"><asp:ListItem Selected disabled>Item #</asp:ListItem></asp:DropDownList>&emsp;

                    <label class="control-label" style="font-family:Calibiri">Type: </label>

                    <asp:TextBox ID="txtType" runat="server" CssClass="form-control" Width="50%"></asp:TextBox>

                    <label class="control-label" style="font-family:Calibri">Model: </label>

                    <asp:DropDownList ID="ddlModel" runat="server" DataSourceID="ModelSource" DataTextField="Model" DataValueField="Model" AutoPostBack="true"></asp:DropDownList>
                    <asp:SqlDataSource ID="ModelSource" runat="server" ConnectionString="<%$ ConnectionStrings:POConnectionString2 %>" SelectCommand="SELECT DISTINCT Model from ItemType WHERE (Type = @Type) Order By Model">
                        <SelectParameters>
                            <asp:ControlParameter Name="Type" ControlID="txtType" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                </div>

            </div>
         </ContentTemplate>
         </asp:UpdatePanel>

和我的.cs代码

protected void ddlID_SelectedIndexChanged(object sender, EventArgs e)
    {
        Utility u = new Utility();
        string conn = u.PO();
        SqlConnection connUser = new SqlConnection(conn);
        SqlCommand cmd = connUser.CreateCommand();
        SqlDataReader sdr = null;

        string que = "SELECT ItemType FROM ItemTransaction WHERE ID ='" + ddlID.SelectedValue + "'";

        connUser.Open();
        cmd.CommandText = que;
        sdr = cmd.ExecuteReader();

        string type = "";

        while (sdr.Read())
        {
            type = sdr.GetString(0);
        }

        txtType.Text = type;


    }

0 个答案:

没有答案