简体   繁体   中英

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? 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>
  1. Try to add DataTextField and DataValueField to the DropDownList.

  2. Delete the attribute ConnectionString , and set the DataFile preporty codebehind. You can not use <%= %> in a server-side control attribute, it will cause parse error

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";
}

You can check this post: 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();  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM