【问题标题】:Guid and DropDownList error?Guid 和 DropDownList 错误?
【发布时间】:2013-02-15 04:10:37
【问题描述】:

我正在尝试在我的 asp.net 应用程序上修复黄页死亡我 dropDownList ddl_userNames 与用户名和 Guid 值列表我使用 SQl 数据 sours 绑定它但我的问题是我有项目列表值 -1 并选择用户和当我加载它给我的页面时,我有图表 asp.net 绑定到这个 ddl_username “Guid 应该包含 32 位数字和 4 个破折号(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)。”我知道这是因为 -1 值可以帮助解决这个问题

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <style type="text/css">
        .style1
        {
            height: 24px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table class="ui-accordion">
        <tr>
            <td>
                <label>Tech User name:</label></td>
            <td>
                <asp:DropDownList ID="ddl_userNames" runat="server" 
                    DataSourceID="SqlDS_techNames" DataTextField="UserName" 
                    DataValueField="UserId" AppendDataBoundItems="True" AutoPostBack="True">
                    <asp:ListItem Value="-1">Select one</asp:ListItem>
                </asp:DropDownList>
                <asp:SqlDataSource ID="SqlDS_techNames" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:Compudata_ProjectManagerConnection %>" 
                    SelectCommand="SELECT [UserId], [UserName] FROM [vw_aspnet_Users]">
                </asp:SqlDataSource>
            </td>
        </tr>
        <tr>
            <td>
               <label>Sesrch terms:</label> </td>
            <td>
                               <asp:DropDownList ID="ddl_SesrchTerms" runat="server" 
                >
                                   <asp:ListItem Value="-1">Select One</asp:ListItem>
                                   <asp:ListItem Value="1">Daily</asp:ListItem>
                                   <asp:ListItem Value="2">Weekly</asp:ListItem>
                                   <asp:ListItem Value="3">Monthly</asp:ListItem>
                               </asp:DropDownList></td>
        </tr>
        <tr>
            <td>
                <label>Date:</label></td>
            <td>
                <asp:TextBox ID="txtb_date" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="style1">
                <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
            </td>
            <td class="style1">
                <asp:Label ID="lbl_msg" runat="server"></asp:Label>
            </td>
        </tr>
    </table>
    <br />
    <br />
    <br />


    <asp:Chart ID="Chart1" runat="server" 
        DataSourceID="SqlDS_Get_Individual_Tech_Service_Chart">
        <Series>
            <asp:Series Name="Series1" ChartType="Pie" XValueMember="billableTypeName" 
                YValueMembers="TotalTime">
            </asp:Series>
        </Series>
        <ChartAreas>
            <asp:ChartArea Name="ChartArea1">
            </asp:ChartArea>
        </ChartAreas>
    </asp:Chart>
    <asp:SqlDataSource ID="SqlDS_Get_Individual_Tech_Service_Chart" runat="server" 
        ConnectionString="<%$ ConnectionStrings:Compudata_ProjectManagerConnection %>" 
        SelectCommand="Get_Individual_Tech_Service_Chart" 
        SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:ControlParameter ControlID="ddl_SesrchTerms" DbType="Int32" 
                Name="SearchTerms" PropertyName="SelectedValue" />
            <asp:ControlParameter ControlID="ddl_techNames" DbType="Guid" Name="TechID" 
                PropertyName="SelectedValue" />
            <asp:ControlParameter ControlID="txtb_date" DbType="DateTime" Name="Date" 
                PropertyName="Text" />
        </SelectParameters>
    </asp:SqlDataSource>
</asp:Content>

【问题讨论】:

  • 使用全零的 GUID 代替 -1。

标签: c# webforms


【解决方案1】:

您总是可以在 page_load 中添加额外的行以插入带有空 guid 的“Select One”

ddl_userNames.Items.Insert(0, new ListItem("Select one", Guid.Empty.ToString()));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-15
    相关资源
    最近更新 更多