模板列的几个问题

nnlyc 2004-08-26 04:39:12
用游标变量从Oracle8i返回一个数据集,打算绑定到datagrid,结构如下:

checkbox | 会员ID | 公司名称

会员ID : user_id
公司名称: companyname

用HyperLinkColumn模板列,怎么绑定companyname?

<asp:HyperLinkColumn
HeaderText="Select an Item"
DataNavigateUrlField="IntegerValue" //(1)
DataNavigateUrlFormatString="detailspage.aspx?id={0}" //(2)
DataTextField="PriceValue" //(3)
DataTextFormatString="{0:c}" //(4)
Target="_blank"/>
(1)和(3)为什么不一样?(3)的应该是companyname
(2).aspx?user_id={0},可以把user_id换成id吗?我不想浏览时看到字段名
(4){0:c}什么意思?
...全文
153 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
gasover 2004-08-26
  • 打赏
  • 举报
回复
在 C# 里面 ,OracleDataReader不包含列名的,所以不能绑定模板列,、
gasover 2004-08-26
  • 打赏
  • 举报
回复
:)
nnlyc 2004-08-26
  • 打赏
  • 举报
回复
呵呵,可以绑定了:)
gasover 2004-08-26
  • 打赏
  • 举报
回复
<asp:HyperLinkColumn
HeaderText="Select an Item"
DataNavigateUrlField="IntegerValue" //(1)
DataNavigateUrlFormatString="detailspage.aspx?id={0}" //(2)
DataTextField="PriceValue" //(3)
DataTextFormatString="{0:c}" //(4)
Target="_blank"/>

你看(3) 的 "PriceValue" 这个不是一个字段名吗? 对了你用的OracleDataReader 阿,
datareader 是不能用来绑定模板列的,你得用DATASET 或者 dataTable
nnlyc 2004-08-26
  • 打赏
  • 举报
回复
那怎么把OracleDataReader的字段绑定到HyperLinkColumn呢?我用的是存储过程,好像很麻烦:(
accpyy 2004-08-26
  • 打赏
  • 举报
回复
2.可以,只要能把值传过去就行,名无所谓的!
4.{0:c}显示price ,后跟以货币格式表示的数字
srz007 2004-08-26
  • 打赏
  • 举报
回复
aspx?user_id={0} 当然,user_id这个名字你随便命 ,比如 FUCK_JANPAN 也没有关系,有问题你找我。

这个强,俺同意,呵呵
goody9807 2004-08-26
  • 打赏
  • 举报
回复


DataGrid的模板列
基于模板的列在datagrid控件中扮演了一个很重要的角色,它们允许你增加任意一种类型的列到datagrid,datagrid通过纯文本的形式或者某种预定义的列类型显示内容。然而,有时预定义的列类型并不能实现我们想要的东西。模板列有四种不同的模板,如图1
Figure 1 DataGrid Column Templates
Name Description
ItemTemplate Contains the template for the items in a DataGrid's column.
<ItemTemplate>
<asp:label runat="server" text= '<%# ... %>'...>
</ItemTemplate>
You can use any combination of HTML text and ASP.NET controls to populate the column.
EditItemTemplate Controls the contents of the item selected for editing in the column of the DataGrid control. Place the controls you need for editing the cell between the opening and closing EditItemTemplate tags.
<EditItemTemplate>
<asp:textbox runat="server" text= '<%# ... %>'...>
</EditItemTemplate>
HeaderTemplate Contains the template for the heading section.
<HeaderTemplate>
<asp:label runat="server" text= "Header"...>
</HeaderTemplate>
If you omit this template, the column header is rendered with a label or a hyperlink if sorting is enabled. By specifying a custom template, you make yourself responsible to provide the user interface needed to enable sorting on the column.
FooterTemplate Contains the template for the footer section of the column. The default value is a null reference.
<FooterTemplate>
<asp:label runat="server" text= "..."...>
</FooterTemplate>
The footer is displayed only if the ShowFooter property of the DataGrid is set to True.

你可能会频繁的使用模板列(ItemTemplate)。它定义了怎么样显示列中的单元格及由哪些元素组成控件的内容。HeaderTemplate 和 FooterTemplate我们就不说了,相信大家都知道是干什么用的。当列的所属行进入编辑模式时,EditItemTemplate属性指明单元格应该怎样变化。但要注意的是,它和datalist控件不一样,datagrid没有选中模板。
当你需要用不规范的方式显示整个列的时候,你的DataGrid应该用基于模板的列。如果你需要显示数据的数据无法用datagrid 提供的普通的模板显示时,这时,模板就是你的最佳选择了。

下面的代码演示了怎样绑定数据到datagrid控件的模板列。
<asp:TemplateColumn runat="server"
HeaderText="heading">
<itemtemplate>
...ASP.NET layout goes here...
</itemtemplate>
</asp:TemplateColumn>
注意模板列和其它类型的列一样,也有一个可用于排序的标题文字。模板列没有直接用于绑定数据源字段的属性。也就是在TemplateColumn类的成员里面,你找不到任何DataField或DataTextField属性。
缺少直接绑定数据源字段的属性是为了更灵活的处理列的显示布局。要呈现一个列,你可以用label控件的text属性,当然也可以用dropdownlist控件或者image控件,这两个控件都没有类似text的属性。结果一样,你都必须用一个数据绑定表达式来绑定数据。在我看来,虽然要写冗长的数据绑定表达式,但它却给了你极大的灵活性。
下面的代码片断演示怎样正确绑定内容到item template:
<asp:label runat="server"
Text='<%# DataBinder.Eval(Container.DataItem,
"lastname") %>'
/>
通过用DataBinder.Eval方法,你能够访问当前数据源的任何一个字段。除此以外,你还可以结合任何的排序表达式来对字段进行排序。这是用其它简单的模板列无法实现的。
noahart 2004-08-26
  • 打赏
  • 举报
回复
坚决支持用FUCK_JAPAN做参数
2002pine 2004-08-26
  • 打赏
  • 举报
回复
说得对
gasover 2004-08-26
  • 打赏
  • 举报
回复
DataNavigateUrlField="IntegerValue" //这个是超链接的地址字段名 在你表中自己选一个字段填上去吧。

DataTextField="PriceValue" // 是个是超链接文本的字段名 也在你表中自己选一个字段填上去吧。 可以用companyname


aspx?user_id={0} 当然,user_id这个名字你随便命 ,比如 FUCK_JANPAN 也没有关系,有问题你找我。

DataTextFormatString="{0:c}" 这个是指定字段的格式的,"{0:c}" 好像是代表价格。,你现在是公司名,当然就不用这个了,DataTextFormatString="{0:c}"这个整段都删了吧。




62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧