0

如何从 c# .net 客户端下拉框中的存储过程 n 中获取数据?我必须尝试以下代码,但这对我不起作用.. :( 谁能告诉我这里出了什么问题?

   <div id="test-area">
        <table border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td>
                    <asp:DropDownList ID="DropDownEventType"  runat="server" CssClass="dropDownEventType" DataSourceID="spdropDownEventType">
                        <asp:ListItem></asp:ListItem>
                    </asp:DropDownList>
                    <asp:AccessDataSource 
                        ConnectionString="<%= ConnectionStrings:ApplicationServices %>"
                        SelectCommand="app_Event_Type_Select" 
                        SelectCommandType="StoredProcedure"  
                        ID="spdropDownEventType" 
                        runat="server"></asp:AccessDataSource>
                </td>
            </tr>
        </table>

    </div>
4

3 回答 3

0
  1. 尝试将 DataTextField 和 DataValueField 添加到 DropDownList。

  2. 删除属性ConnectionString,并设置DataFilepreporty codebehind。不能<%= %>在服务器端控件属性中使用,会导致解析错误

aspx

<table border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td>
            <asp:DropDownList ID="DropDownEventType"  runat="server" CssClass="dropDownEventType" DataSourceID="spdropDownEventType" 
                DataTextField="yourEventName" 
                DataValueField="yourEventValue">
            </asp:DropDownList>
            <asp:AccessDataSource 
                SelectCommand="app_Event_Type_Select" 
                SelectCommandType="StoredProcedure"  
                ID="spdropDownEventType" 
                runat="server"></asp:AccessDataSource>
        </td>
    </tr>
</table>

CS:

protected void Page_Load(object sender, EventArgs e)
{
    spdropDownEventType.DataFile = "your access db file path";
}
于 2012-08-04T04:34:40.353 回答
0

你可以查看这篇文章:http ://forums.asp.net/t/1486795.aspx/1

在代码隐藏中,您需要这样的东西:

DropDownEventType.DataTextField="TextFieldColumnName"
DropDownEventType.DataValueField="ValueFieldColumnName"
DropDownEventType.DataBind()   
于 2012-08-04T04:35:05.220 回答
0
 <div id="test-area">
    <table border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td>
                <asp:DropDownList ID="DropDownEventType"  runat="server" CssClass="dropDownEventType" DataSourceID="spdropDownEventType">
                    DataTextField="Name" 
                    DataValueField="EventTypeID">
                </asp:DropDownList>
                <asp:AccessDataSource 
                    ConnectionString="<%= ConnectionStrings:ApplicationServices %>"
                    SelectCommand="app_Event_Type_Select" 
                    SelectCommandType="StoredProcedure"  
                    ID="spdropDownEventType" 
                    runat="server"></asp:AccessDataSource>
            </td>
        </tr>
    </table>

</div>

或者

在后面的代码中绑定下拉

DropDownEventType.DataSource = datable value;   
DropDownEventType.DataTextField="Name";
DropDownEventType.DataValueField="EventTypeID";
DropDownEventType.DataBind();  
于 2012-08-04T04:51:23.980 回答