📄 kj08-04-02.txt
字号:
8.4.2 手工指定字段的DataGrid控件
8.4.2.1 新增加的事件
在使用DataGrid控件操作数据库时,若使用手工指定字段的方式,则可使用更多的功能并获得更大的灵活性,当然,在这种方式下,需要进行较多的设置,编码也比较复杂。
手工指定字段的DataGrid控件的声明语法如下:
<ASP:DataGrid Runat="Server" Id="…" DataSource='<%# … %>'
AllowPaging="True | False" AllowSorting="True | False"
AutoGenerateColumns="False" BackImageUrl="URL" CellPadding="n" CellSpacing="n"
DataKeyField="…" GridLines="None | Horizontal | Vertical | Both"
HorizontalAlign="Center |Justify | Left | NotSet | Right" PageSize="n"
ShowFooter="True | False" ShowHeader="…" OnItemCreated="…"
OnpageIndexChanged="…" OnSortCommand="…" OnCancelCommand="…"
OnEditCommand="…" OnItemCommand="…" OnUpdateCommand="…">
<HeaderStyle BorderColor="…" … />
<ItemStyle Font-Bold="True|False" … />
<AlternatingItemStyle ForeColor="…" … />
<SeparatorStyle BackColor="…" … />
<FooterStyle BorderColor="…" … />
<PagerStyle BorderColor="…" … />
<EdititemStyle BorderColor="…" … />
<Columns>
<ASP:BoundColumn DataField="…" FooterText="…" HeaderImageUrl="URL"
HeaderText="…" SortExpression="…"
Visible="True | False" ReadOnly="True | False"
FooterStyle-property="…" HeaderStyle-property="…" ItemStyle-property="…"/>
<ASP:ButtonColumn ButtonType="LinkButton | PushButton"
DataTextField="…" FooterText="…" HeaderImageUrl="URL" HeaderText="…"
Text="…" Visible=" True | False"/>
<ASP:EditCommandColumn ButtonType=" LinkButton | PushButton"
CancelText="…" EditText="…" UpdateText="…"
FooterText="…" HeaderImageUrl="URL"
HeaderText="…" ReadOnly="True | False" Visible="True | False"/>
<ASP:HyperLinkColumn DataNaviGateUrlField="..." DataTextfield="…"
Footertext="…" HeaderImageUrl="URL" HeaderText="…"
Target="…" Text="…" Visible=" True | False"/>
<ASP:TemplateColumn FooterText="…" HeaderImageUrl="URL" HeaderText="…"
ReadOnly="True | False" Visible="True | False">
<HeaderTemplate></HeaderTemplate >
<ItemTemplate></ItemTemplate >
<EditItemTemplate></EditItemTemplate >
<FooterTemplate></FooterTemplate >
</ASP:TemplateColumn>
</Columns>
</ASP:DataGrid>
在手工指定字段的方式下,DataGrid控件可使用的属性,除位于<Columns></Columns>之间的模板外,与自动生成字段方式下的属性相同,使用方式也类似。而位于<Columns></Columns>之间的模板,是这种方式中最具使用价值的部分,其使用方法将在后文详细介绍。至于可用事件,在手工指定字段的方式下,除可使用自动产生字段方式下的所有事件外,还可以使用下列事件:
* OnEditCommand="…":当单击DataGrid控件的编辑功能按钮时会触发此事件。参数为DataGridCommandEventArgds,其中Item用于获取按钮控件所在的DataGrid对象。
* OnUpdateCommand="…":当选取DataGrid控件的更新功能按钮时会触发此事件,参数为DataGridCommandEventArgds。
* OnCancelCommand="…":当单击DataGrid控件的取消功能按钮时会触发此事件,参数为DataGridCommandEventArgs。
* OnItemCommand="…":当单击DataGrid控件的Button、ImageButton或LinkButton控件时会触发此事件,其参数也是DataGridCommandEventArgds。
8.4.2.2 BoundColumn字段
BoundColumn字段用于显示记录。在自动生成字段方式下所生成的字段其实就是BoundColumn。
BoundColumn字段的常用属性如下:
* DataField="…":给出或设置所要显示字段的名称。
* FooterStyle-property="…":给出或设置页脚的显示格式。Property指的是TableitemStyle样式对象,例如FooterStyle-HrizontalAlign="Center"表示将此字段的页脚水平对齐方式设置为居中。
* FooterText="…":给出或设置此字段在DataGrid控件的页脚所要显示的内容,可包含HTML标记。
* HeaderImageUrl="URL":给出或设置此字段的标题所要显示图片的相对或绝对地址,若同时设置HeaderImageUrl属性及Headertext属性,则以HeaderImageUrl属性为准。
* Headerstyle-property="…":给出或设置此字段标题的显示格式,Property指的是TableitemStyle样式对象。
* HeaderText="…":给出或设置字段标题所要显示的文字,可以包含HTML标记,若同时设置HeaderImageUrl属性及HeaderText属性,则以HeaderImageUrl属性为准。
* ItemStyle-Property="…":给出或设置字段数据的显示格式,Property指的是TableitemStyle样式对象。例如ItemStyle-Font-Bond="True"表示将字段中的数据显示为粗体。
* ReadOnly="True | False":给出或设置此字段的内容的只读状态,False表示允许编辑,True表示不允许编辑,默认为False。
* SortExpression="…":给出或设置产生OnSortCommand事件时所要排序的字段名称(例如"书名")或排序字符串(例如"书名 Desc")。
* Visible="True | False":给出或设置是否显示此字段,默认为True。
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -