[英]how to get the data from stored proc n show on the dropdownbox in c# .net client side?
如何从c#.net客户端下拉列表中显示的存储的proc 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>
尝试将DataTextField和DataValueField添加到DropDownList。
删除属性ConnectionString
,并在其后面设置DataFile
前置代码。 您不能在服务器端控件属性中使用<%= %>
,它将导致解析错误
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";
}
您可以查看此帖子: http : //forums.asp.net/t/1486795.aspx/1
在代码隐藏中,您需要这样的东西:
DropDownEventType.DataTextField="TextFieldColumnName"
DropDownEventType.DataValueField="ValueFieldColumnName"
DropDownEventType.DataBind()
<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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.