如何从数据集中获取单列值 [英] How to get Single column value from the dataset

查看:100
本文介绍了如何从数据集中获取单列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友



我获取整个数据集,但我希望获得单列投标我的下拉列表,但其返回水平值



这里是我的代码问题出在哪里?



 DataSet ds =  new  DataSet(); 
ds = Content_Data.GetContents();
ddlPageName.DataSource = ds.Tables [ 0 ]。行[ 0 ] [ PageName]。ToString();
ddlPageName.DataBind();

解决方案

您必须在Dropdownlist中添加列表项以分配值ds.Tables [0] .Rows [0] [ 页面名称]的ToString();到那个特定的清单项目

例如

清单< system.web.ui.webcontrols.listitem> colors =  new  List< system.web.ui.webcontrols.listitem>(); 
colors.Add( new ListItem( 选择值 0));
colors.Add( new ListItem(ds.Tables [ 0 ]。行[ 0 ] [ PageName]。ToString( ), 1));

< / system.web.ui.webcontrols.listitem > < / system.web.ui.webcontrols.listitem >



然后将此列表绑定到您的下拉列表



 ddlPageName.DataSource = colors; 
ddlPageName.DataBind();


Hello friends

I fetch whole the dataset but i want to get single column to bid my dropdown but its return horizontal value

here is my code where is the problem?

DataSet ds = new DataSet();
ds = Content_Data.GetContents();
ddlPageName.DataSource = ds.Tables[0].Rows[0]["PageName"].ToString();
ddlPageName.DataBind();

解决方案

You must add list item in Dropdownlist for assigning the value ds.Tables[0].Rows[0]["PageName"].ToString(); to that perticular list Item
For example

List<system.web.ui.webcontrols.listitem> colors = new List<system.web.ui.webcontrols.listitem>();
colors.Add(new ListItem("Select Value", "0"));
colors.Add(new ListItem(ds.Tables[0].Rows[0]["PageName"].ToString(), "1"));

</system.web.ui.webcontrols.listitem></system.web.ui.webcontrols.listitem>


And then bind this List to your drop down list

ddlPageName.DataSource = colors;
ddlPageName.DataBind(); 


这篇关于如何从数据集中获取单列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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