gpt4 book ai didi

c# - 下拉列表选择的项目文本总是返回第一个项目文本

转载 作者:太空狗 更新时间:2023-10-29 21:04:48 25 4
gpt4 key购买 nike

我正在使用此代码从数据库中填充下拉列表。

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()。并在 Button Click 事件上重新设置 selecteditm.text

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

最佳答案

在 .aspx 页面中:

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

对于下拉列表控件将 EnableViewState 属性设置为 true。

在 .aspx.cs 页面中:

在 PageLoad 事件中检查以下内容:

if(!IsPostBack)
{
fillcountry();
}

关于c# - 下拉列表选择的项目文本总是返回第一个项目文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23052739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com