如何在asp.net中将数据与其他文本绑定? [英] How to bind data with additional text in asp.net?

查看:67
本文介绍了如何在asp.net中将数据与其他文本绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将数据库中的月份列表绑定到asp.net中的DropDownList。

我在数据库中的数据是这样的



------

24

36

$



这里我想绑定月份列表如

24个月

36个月

60个月



那么任何人都可以帮助我吗?

推荐答案

在数据表dt中获取月份数据


然后执行以下操作:





for(int i = 0; i< ; dt.rows.count; i ++)>

{

dropdown.Items.Add(dt.Rows [i] [Months]。ToString()+ 月份);

}
take month data in datatable dt

then do the following:


for(int i=0;i<dt.rows.count;i++)>
{
dropdown.Items.Add(dt.Rows[i]["Months"].ToString()+" Months");
}


下面的代码片段可能对您有所帮助:



The below snippet might help you:

DataTable dt=GetMonthsFromDB();//Some method you have written to get the data from the DB
dropdownlist1.DataSource=dt;
dropdownlist1.DataTextField=dt.Columns[0].ToString() + "Months";
dropdownlist1.DataValueField=dt.COlumns[0].ToString();
dropdownlist1.DataBind();





上面的代码段假设您的数据表dt中只有一列,如果不,那么你可以相应地更改列索引。这应该工作......它...



-Anurag



The above snippet assumes that you have only one column coming in your datatable dt, if no, then you can change the column index accordingly..This should work..try it..

-Anurag


在sql查询中进行更改以显示您所需的值...如果您可以发布用于填充下拉列表的SQL查询,我将能够帮助您查询
Make changes in the sql query for displaying values as required by you... if you can post the SQL Query you are using for populating drop down, i will be able to help you with Query also


这篇关于如何在asp.net中将数据与其他文本绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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