输出数据库值在下拉列表中大写 [英] Output database values to dropdown in uppercase

查看:134
本文介绍了输出数据库值在下拉列表中大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的形式(asp.net),某些领域正在从数据库表填充。其中之一是与国家名称一个DropDownList。这些名称在表小写的,但我想做到以下几点:

I have a very simple form (in asp.net), some of the fields being populated from db tables. One of them is a dropdownlist with country names. These names are in lowercase in the table, but I would like to do the following:


  • 以大写
  • 的第一个字母显示出来
  • 保持其价值小写,使表单提交时,这个国家的名字存储为他们检索的方式相同。

  • display them with the first letter in uppercase
  • keep their value in lowercase, so that when the form is submitted, the country names are stored the same way as they were retrieved.

恩。在HTML中,我们可能有这样一个选项:

ex. in html we may have an option like this:

<option value="montenegro">Montenegro</option>

用户看到黑山,但提出黑山。

The user sees "Montenegro", yet submits "montenegro".

我知道这可能会以其他方式来实现(如例查询转换,但我很好奇,这个方法是否可行与否)。
此外,也许这个问题的答案确实存在,但我没能找到一个,我认为适合的问题,是不够清楚。

I know this could be implemented in other ways (like converting the case with the queries, but I was curious whether this method is possible or not). Also, maybe answers to this question do exist, but I was not able to find one that I thought fit the question and was clear enough.

推荐答案

使用此方法:

protected string UppercaseFirst(string s)
{
    if (string.IsNullOrEmpty(s))
        return string.Empty;

    return char.ToUpper(s[0]) + s.Substring(1);
}

在下拉菜单调用数据绑定在foreach:

After dropdown databind call the foreach :

    dropDown.DataTextField = "ColumnName";
    dropDown.DataValueField = "ColumnName";
    dropDown.DataBind();

 foreach (ListItem t in dropDown.Items)
        t.Text = UppercaseFirst(t.Text);

这篇关于输出数据库值在下拉列表中大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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