下拉列表选择的项目文本始终返回第一个项目文本 [英] Dropdownlist selected item text always returning the first item text

查看:115
本文介绍了下拉列表选择的项目文本始终返回第一个项目文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码从数据库填充dropdownlist。

  public void fillcountry()
{
BL obj = new BL();
DataSet ds = obj.dss(select * from Country);
drplistcountry.DataSource = ds;
drplistcountry.DataTextField =CountryName;
drplistcountry.DataValueField =CountryId;
drplistcountry.DataBind();
drplistcountry.Items.Insert(0,new ListItem( - Select--,0));
}

我正在页面load()事件中使用这个fillcountry()。
和重新选择buttonit事件中的selectitm.text



drplistcountry始终显示第一个索引文本,如何解决?

解决方案

在.aspx页面中:

 <%@ Title =Home PageLanguage =C#AutoEventWireup =true
CodeBehind =Default.aspx.csInherits =WebApplication4._Default
EnableViewState =true%>

对于Dropdownlist控件
EnableViewState 属性设置为true。 / p>

在.aspx.cs页面中:



在PageLoad事件检查中如下:

  if(!IsPostBack)
{
fillcountry();
}


i am using this code to fill dropdownlist from database.

public void fillcountry()
{
    BL obj = new BL();
    DataSet ds = obj.dss("select * from Country  ");
    drplistcountry.DataSource = ds;
    drplistcountry.DataTextField = "CountryName";
    drplistcountry.DataValueField = "CountryId";
    drplistcountry.DataBind();
    drplistcountry.Items.Insert(0, new ListItem("--Select--", "0"));
}

i am Using this fillcountry() in page load() event. and Rerutning selecteditm.text on Button Click event

drplistcountry is always showing First index text , How to solve it?

解决方案

In .aspx page:

<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication4._Default" 
EnableViewState="true" %>

For Dropdownlist Control set EnableViewState property to true.

In .aspx.cs page:

In PageLoad event check for following:

if(!IsPostBack)
{ 
    fillcountry();
}

这篇关于下拉列表选择的项目文本始终返回第一个项目文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆