[英]how to get the data from stored proc n show on the dropdownbox in c# .net client side?
How can I get the data from stored proc n show on the dropdownbox in c# .net client side? 如何从c#.net客户端下拉列表中显示的存储的proc n中获取数据? I have to tried the follwoing code but this is not working for me .. :( can anyone tell me what is going wrong here?
我必须尝试以下代码,但这对我不起作用..:((有人可以告诉我这里出了什么问题吗?
<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>
Try to add DataTextField and DataValueField to the DropDownList. 尝试将DataTextField和DataValueField添加到DropDownList。
Delete the attribute ConnectionString
, and set the DataFile
preporty codebehind. 删除属性
ConnectionString
,并在其后面设置DataFile
前置代码。 You can not use <%= %>
in a server-side control attribute, it will cause parse error 您不能在服务器端控件属性中使用
<%= %>
,它将导致解析错误
aspx 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: CS:
protected void Page_Load(object sender, EventArgs e)
{
spdropDownEventType.DataFile = "your access db file path";
}
You can check this post: http://forums.asp.net/t/1486795.aspx/1 您可以查看此帖子: http : //forums.asp.net/t/1486795.aspx/1
On codebehind, you need something like this: 在代码隐藏中,您需要这样的东西:
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>
OR 要么
Bind Drop down in code behind 绑定下拉代码
DropDownEventType.DataSource = datable value;
DropDownEventType.DataTextField="Name";
DropDownEventType.DataValueField="EventTypeID";
DropDownEventType.DataBind();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.