Guid和DropDownList错误?

时间:2013-02-14 19:48:39

标签: c# webforms

我正在尝试在我的asp.net应用程序上修复死亡的黄页我使用用户名和Guid值列表的dropDownList ddl_userNames我使用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>

1 个答案:

答案 0 :(得分:1)

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

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