[英]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.