|
反馈BUG
程序版本: |
6.1.0 |
浏览器: |
Chrome |
BUG截图: |
|
BUG地址: |
- |
本帖最后由 zj880808 于 2020-6-24 10:56 编辑
前端代码:
<f:SimpleForm ID="SimpleForm1" CssClass="blockpanel" BodyPadding="10px" runat="server" EnableCollapse="false"
ShowBorder="true" Title="下拉列表(初始值为空,可编辑,强制选择)" ShowHeader="true">
<Items>
<fropDownList runat="server" ID="DropDownList1" EnableEdit="true" AutoSelectFirstItem="false" EmptyText="请选择一项">
</fropDownList>
<f:Button ID="btnSelectItem6" Text="选中[可选项6]" runat="server"
CssClass="marginr">
</f:Button>
<f:Button ID="btnGetSelection" Text="获取此下拉列表的选中项" runat="server">
</f:Button>
</Items>
</f:SimpleForm>
后端代码:
protected void Page_Load(object sender, EventArgs e)
{
using (SqlConnection getconn = new SqlConnection(ConfigurationManager.AppSettings["connstr"].ToString()))
{
try
{
DataSet ds = new DataSet();
getconn.Open();
SqlDataAdapter sda = new SqlDataAdapter("select name,database_id from sys.databases",getconn);
sda.Fill(ds, "master");
DropDownList1.DataTextField = "name";
DropDownList1.DataValueField = "database_id";
DropDownList1.DataSource = ds.Tables[0];
DropDownList1.DataBind();
}
catch(Exception se)
{
throw se;
}
}
}
protected void btnSelectItem6_Click(object sender, EventArgs e)
{
}
protected void btnGetSelection_Click(object sender, EventArgs e)
{
if (DropDownList1.SelectedItem != null)
{
labResult.Text = String.Format("选中项:{0}(值:{1})", DropDownList1.SelectedItem.Text, DropDownList1.SelectedValue);
}
else
{
labResult.Text = "无选中项";
}
}
}
代码大部分都是直接复制的在线示例,唯一的区别就是数据是从数据库获取绑定的。
DataTable table = new DataTable();
DataColumn column1 = new DataColumn("MyText", typeof(String));
DataColumn column2 = new DataColumn("MyValue", typeof(String));
table.Columns.Add(column1);
table.Columns.Add(column2);
DataRow row = table.NewRow();
row[0] = "可选项1";
row[1] = "1";
table.Rows.Add(row);
row = table.NewRow();
row[0] = "可选项2";
row[1] = "2";
table.Rows.Add(row);
row = table.NewRow();
row[0] = "可选项3";
row[1] = "3";
table.Rows.Add(row);
row = table.NewRow();
row[0] = "可选项4";
row[1] = "4";
table.Rows.Add(row);
row = table.NewRow();
row[0] = "可选项5";
row[1] = "5";
table.Rows.Add(row);
row = table.NewRow();
row[0] = "可选项6";
row[1] = "6";
table.Rows.Add(row);
row = table.NewRow();
row[0] = "可选择项7";
row[1] = "7";
table.Rows.Add(row);
row = table.NewRow();
row[0] = "可选择项8";
row[1] = "8";
table.Rows.Add(row);
row = table.NewRow();
row[0] = "可选择项9";
row[1] = "9";
table.Rows.Add(row);
row = table.NewRow();
row[0] = "这是一个很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长很长的可选项";
row[1] = "10";
table.Rows.Add(row);
DropDownList1.DataTextField = "MyText";
DropDownList1.DataValueField = "MyValue";
DropDownList1.DataSource = table;
DropDownList1.DataBind();
通过这种方式绑定数据问题依旧。
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|