在<asp:datagridid=
<FooterStyleForeColor=
<SelectedItemStyleFont
<AlternatingItemStyleBackColor=
<ItemStyleForeColor=
<HeaderStyleFont
說明:
(
<asp:BoundColumnDataField=
說明:
(
(
形式為{A:Bxx}
其中A值只能設置為
冒號後的字符(常規示例中為B)指定值的顯示格式
C 以貨幣格式顯示數值
D 以十進制格式顯示數值
E 以科學記數法(指數)格式顯示數值
F 以固定格式顯示數值
G 以常規格式顯示數值
N 以數字格式顯示數值
X 以十六進制格式顯示數值
(
(
(
<asp:TemplateColumnHeaderText=
<ItemTemplate>
<asp:LabelText=
</ItemTemplate>
<EditItemTemplate>
<selectname=
<%=ActorClass
</select>
</EditItemTemplate>
</asp:TemplateColumn>
說明:
(
<asp:TemplateColumnHeaderText=
<ItemTemplate></ItemTemplate>
</asp:TemplateColumn>
(
<asp:TemplateColumn>
<HeaderTemplate>
<b>Tax</b>
</HeaderTemplate>
<ItemTemplate>
<asp:Label
Text=
runat=
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox
Text=
runat=
</EditItemTemplate>
<FooterTemplate>
<asp:HyperLinkid=
Text=
NavigateUrl=
runat=
</FooterTemplate>
</asp:TemplateColumn>
(
<asp:TemplateColumn>
<ItemTemplate>
<asp:Label
Text=
runat=
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox
Text=
runat=
</EditItemTemplate>
</asp:TemplateColumn>
在正常狀態
在編輯狀態
(
<asp:TemplateColumnHeaderText=
<ItemTemplate>
<asp:LabelID=
<%#DataBinder
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownListid=
<asp:ListItemValue=
<asp:ListItemValue=
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
在正常狀態
在編輯狀態
(
還未做過
<asp:ButtonColumn
HeaderText=
ButtonType=
Text=
CommandName=
(
(
<asp:EditCommandColumnButtonType=
(
<asp:HyperLinkColumnText=
(
設置Text和NavigateUrl屬性
(
A
則再設置DataTextFormatString字段
B
用DataTextField=
C
DataNavigateUrlField=
在DataGrid標簽中加入
OnUpdateCommand=
在codeBehind頁面加入如下代碼
///響應編輯按鈕
publicvoidDataGrid
{
DataGrid
if(Request
Common
else
Common
}
///響應取消按鈕
publicvoidDataGrid
{
DataGrid
if(Request
Common
else
Common
}
///響應更新按鈕
publicvoidDataGrid
{
TextBoxClassNameText=(TextBox)e
stringclassName=ClassNameText
intclassID=Int
TextBoxorderID
intorderID=Int
ActorClass
DataGrid
if(Request
Common
else
Common
}
說明
(
MethodName(Objectsender
(
A
TextBoxClassNameText=(TextBox)e
stringclassName=ClassNameText
B
方法一
intclassID;
classID=Int
方法二
DropDownListbbb=(DropDownList)e
stringddpValue=bbb
C
boolboolEnabled=((CheckBox)e
Stringstr
if(boolEnabled)
{
str
}
else
{
str
}
賦值給str
D
stringstoryID=(e
在DataGrid控件標簽中加入如下代碼
OnPageIndexChanged=
在後台中加入如下代碼
///<summary>
///響應分頁事件
///</summary>
///<paramname=
///<paramname=
publicvoidDataGrid
{
DataGrid
DataBind();
}
一般用些事件來
OnItemDataBound=
///<summary>
///響應DataGrid綁定事件
///</summary>
///<paramname=
///<paramname=
publicvoidDataGrid
{
if(e
{
e
e
}
elseif(e
{
e
e
}
}
在DataGrid控件標簽中加入如下代碼
OnItemCommand=
在後台中加入如下代碼
publicvoidItemsGrid_Command(Objectsender
{
switch(((LinkButton)e
{
case
intclassID=Int
ActorClass
if(Request
Common
else
Common
break;
//Addothercaseshere
//theDataGridcontrol
case
intactorID=Int
ActorClass
if(Request
Common
else
Common
break;
case
intactorclassID=Int
stringorderID=(e
ActorClass
if(Request
Common
else
Common
break;
case
actorclassID=Int
orderID=(e
ActorClass
if(Request
Common
else
Common
break;
default:
//Donothing
break;
}
}
以下三個都是
<asp:TemplateColumnHeaderText=
<ItemTemplate>
<%#ActorClassManage
</ItemTemplate>
</asp:TemplateColumn>
publicstaticstringhasLeaf(stringid
{
stringlRtn=
if(Int
lRtn=
else
lRtn=
returnlRtn;
}
<asp:TemplateColumnHeaderText=
<ItemTemplate>
<asp:LinkButtonText=
</ItemTemplate>
</asp:TemplateColumn>
publicstaticstringIsHidden(stringid
{
stringlRtn=
if(enabled==true)
{
lRtn=
}
else
{
lRtn=
}
returnlRtn;
}
publicstaticvoidSort(stringactorclassID
{
stringtemp=
if(Int
{
temp+=
}
if(Int
{
temp+=
}
}
將下列代碼放於包含<DataGrid>的form中去
<palign=
<asp:labelid=
<asp:labelid=
<asp:linkbuttonid=
Font
<asp:linkbuttonid=
Font
<asp:linkbuttonid=
Font
<asp:linkbuttonid=
Font
</p>
後台代碼
privatevoidPage_Load(objectsender
{
//在此處放置用戶代碼以初始化頁面
btnFirst
btnPrev
btnNext
btnLast
//綁定數據源
if(!Page
{
OpenDatabase();
BindGrid();
}
}
//用於顯示
privatevoidShowStats()
{
lblCurrentIndex
lblPageCount
}
//響應分頁按鈕
publicvoidPagerButtonClick(objectsender
{
stringarg=((LinkButton)sender)
switch(arg)
{
case
if(MyDataGrid
{
MyDataGrid
}
break;
case
if(MyDataGrid
{
MyDataGrid
}
break;
case
MyDataGrid
break;
default:
MyDataGrid
break;
}
BindGrid();
ShowStats();
}
From:http://tw.wingwit.com/Article/program/net/201311/12340.html