小编SUS*_*SAN的帖子

ASP.Net下拉列表没有返回selectedindexchanged事件的索引

我有一个dropdownlist控件,其中有一个正确触发的selectedindexchanged 事件.但是,从列表中选择项目时,返回到selectedindexchanged事件的索引值不会更改; 列表框弹出列表中的第一个项目.任何帮助,将不胜感激.〜苏珊〜

ASP DROP DOWN LIST控件:

 <asp:DropDownList ID="CuisineList" runat="server" Width="100" 
    AutoPostBack = "true" onselectedindexchanged="CuisineList_SelectedIndexChanged" >
 </asp:DropDownList>
Run Code Online (Sandbox Code Playgroud)

在PAGELOAD活动中控制数据:

 protected void Page_Load(object sender, EventArgs e)
 {
    //Load drop down lists for restaurant selection

    BLgetMasterData obj = new BLgetMasterData();

    var cusineList = obj.getCuisines();
    CuisineList.DataSource = cusineList;
    CuisineList.DataBind();
    CuisineList.Items.Insert(0, "Any");
Run Code Online (Sandbox Code Playgroud)

SELECTEDINDEXCHANGEDEVENT:

   protected void CuisineList_SelectedIndexChanged(object sender, EventArgs e)
    {

        if (IsPostBack)
        {
            string def = this.CuisineList.SelectedItem.Value;
            //aLWAYS returns index '0'
        }
    }
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net drop-down-menu

3
推荐指数
1
解决办法
7143
查看次数

ASP.Net LINQ数据源错误是ListView

我有一个成功的查询,从RESTAURANT数据库的REST_NAME columen返回8个项目.我有一个成功的数据绑定,但当我尝试访问LivtView中的项时,我收到一个错误:'System.String'不包含名为'REST_NAME'的属性.

来自数据访问层的LINQ查询:

public IEnumerable<string> getRestaurants(int cuisineID)
{
    var restaurantList = from RESTAURANT in db.RESTAURANTs
                         where RESTAURANT.CUISINE_ID == cuisineID
                         orderby RESTAURANT.REST_NAME ascending
                         select RESTAURANT.REST_NAME;
    return restaurantList;
} 
Run Code Online (Sandbox Code Playgroud)

业务逻辑层中的功能:

public class BLgetRestaurants
{
    public IEnumerable<string> getRestaurants(int cuisineID)
    {
        DLgetRestaurants obj = new DLgetRestaurants();
        var restaurantList = obj.getRestaurants(cuisineID);
        return restaurantList;
    }
}
Run Code Online (Sandbox Code Playgroud)

业务层功能的前端调用:

BLgetRestaurants obj = new BLgetRestaurants();
var restaurantListing = obj.getRestaurants(cuisineID);
ListRestaurants.DataSource = restaurantListing;
ListRestaurants.DataBind();
Run Code Online (Sandbox Code Playgroud)

*最后,通过ListView调用获取REST_NAME数据:**

<ItemTemplate>
    <div id="RestName"><%#Eval("REST_NAME") %></div><br />
     <div id="ListItems">
          <div id="RestCuisine">Cuisine: </div>
          <div id="RestCity">Location: </div>
          <div id="RestAvgRating">Average …
Run Code Online (Sandbox Code Playgroud)

linq asp.net evaluation listview

1
推荐指数
1
解决办法
490
查看次数

标签 统计

asp.net ×2

.net ×1

c# ×1

drop-down-menu ×1

evaluation ×1

linq ×1

listview ×1