DataNavigateUrlField="IntegerValue" //这个是超链接的地址字段名 在你表中自己选一个字段填上去吧。DataTextField="PriceValue" // 是个是超链接文本的字段名 也在你表中自己选一个字段填上去吧。 可以用companyname
aspx?user_id={0} 当然,user_id这个名字你随便命 ,比如 FUCK_JANPAN 也没有关系,有问题你找我。DataTextFormatString="{0:c}" 这个是指定字段的格式的,"{0:c}" 好像是代表价格。,你现在是公司名,当然就不用这个了,DataTextFormatString="{0:c}"这个整段都删了吧。
aspx?user_id={0} 当然,user_id这个名字你随便命 ,比如 FUCK_JANPAN 也没有关系,有问题你找我。DataTextFormatString="{0:c}" 这个是指定字段的格式的,"{0:c}" 好像是代表价格。,你现在是公司名,当然就不用这个了,DataTextFormatString="{0:c}"这个整段都删了吧。
解决方案 »
- GridView onrowupdating 修改数据 值不变
- ASP.NET,,,,
- 急需VS 文档
- wap开发 用移动web窗体控件开发兼容性和稳定性差???
- Infragistics中ultraGrid控件的滚动条问题
- 请问一个正则表达式?
- 怎样在asp.net中存取图片[用vb.net+oracle8i实现]?
- 都来留下 QQ 吧,大家互相帮助,在线解决问题,记得牢固,这有多好。
- 我的分全都给你,关于设置ODBC数据库路径问题,在线急等!
- 新安装win2003与vs.net2003,新建项目后,用浏览器浏览默认的webform1,出现如下错误!
- 有哪位大哥可以讲讲txt_User_Id.Text.Replace(" ","")到底有什么用???
- 我装了iis后怎么开启它?还有asp.net默认是开的还是关的?
基于模板的列在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方法,你能够访问当前数据源的任何一个字段。除此以外,你还可以结合任何的排序表达式来对字段进行排序。这是用其它简单的模板列无法实现的。
4.{0:c}显示price ,后跟以货币格式表示的数字
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