首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

100分dropdownlist数据绑定后选择上拉列表后返回的值不变或为空

2012-08-10 
100分求助:dropdownlist数据绑定后选择下拉列表后返回的值不变或为空前台代码:asp:DropDownList IDFanw

100分求助:dropdownlist数据绑定后选择下拉列表后返回的值不变或为空
前台代码:
<asp:DropDownList ID="Fanwei" runat="server" AutoPostBack="true"> </asp:DropDownList>

C# code
if (!IsPostBack)        {            SqlDataReader dr = this.Executeprocedure1("SelectZhuceCompanyType");            if (dr.Read())            {                Fanwei.Items.Add(new ListItem(dr["ProductCatalogName_nvarchar"].ToString(), dr["ProductCatalogId_nvarchar"].ToString()));            }            DataSet ss = new DataSet();            this.Executeprocedure("SelectZhuceCompanyType", ref ss);            Fanwei.DataSource = ss.Tables[0].DefaultView;            Fanwei.DataTextField = "ProductCatalogName_nvarchar";            Fanwei.DataValueField = "ProductCatalogId_nvarchar";            Fanwei.Items.Clear();            Fanwei.DataBind();            ss.Clear();            ss.Dispose();        }


选择下拉列表中的某一项之后,string selectedid=Fanwei.SelectedValue;的值总是第一项的值,不管选哪项都是第一个值。

这是其中一个问题。


再就是:

<asp:DropDownList ID="Fanwei" runat="server" AutoPostBack="true" onselectedindexchanged="Fanwei_SelectedIndexChanged">
</asp:DropDownList>

当选择一项之后无法执行Fanwei_SelectedIndexChanged事件,实在是郁闷啦,请哪位大哥帮帮小弟吧,我用了好多天都没解决这个问题。



[解决办法]
方法用错了注意大小写
 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="1">所有用户</asp:ListItem>
<asp:ListItem Value="2">已审的用户</asp:ListItem>
<asp:ListItem Value="3">待审的用户</asp:ListItem>
<asp:ListItem Value="4">被锁的用户</asp:ListItem>
<asp:ListItem Value="5">审核未通过</asp:ListItem>
</asp:DropDownList>

后台
C# code
    protected void Page_Load(object sender, EventArgs e)    {              if (!IsPostBack)        {            bindxx();        }    }    public void bindxx()    {        DataSet ds = gc.select_gyss(selecttype);        GridView1.DataSource = ds;        GridView1.DataBind();        ds.Clear();        ds.Dispose();    }
[解决办法]
DataSet ss = new DataSet();
this.Executeprocedure("SelectZhuceCompanyType", ref ss);
Fanwei.DataSource = ss.Tables[0].DefaultView;
Fanwei.DataTextField = "ProductCatalogName_nvarchar";
Fanwei.DataValueField = "ProductCatalogId_nvarchar";
Fanwei.DataBind();

SqlDataReader dr = this.Executeprocedure1("SelectZhuceCompanyType");
if (dr.Read())
{
Fanwei.Items.Insert(0,new ListItem(dr["ProductCatalogName_nvarchar"].ToString(), dr["ProductCatalogId_nvarchar"].ToString()));
}
单步跟踪看看Fanwei.SelectedValue是否有值

[解决办法]
HTML code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Table.aspx.cs" Inherits="Table" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title>无标题页</title></head><body>    <form id="form1" runat="server">    <div>                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"             onselectedindexchanged="DropDownList1_SelectedIndexChanged"             DataSourceID="SqlDataSource1" DataTextField="Opinion" DataValueField="VoteID">        </asp:DropDownList>                <asp:SqlDataSource ID="SqlDataSource1" runat="server"             ConnectionString="<%$ ConnectionStrings:db_11ConnectionString %>"             SelectCommand="SELECT [VoteID], [Opinion] FROM [Vote]"></asp:SqlDataSource>            </div>    </form></body></html> 

热点排行