




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
PAGE95/NUMPAGES951.GridView代碼分頁排序:效果圖:
1.AllowSorting設(shè)為True,aspx代碼中是AllowSorting="True";
2.默認(rèn)1頁10條,如果要修改每頁條數(shù),修改PageSize即可,在aspx代碼中是PageSize="12"。
3.默認(rèn)的是單向排序的,右擊GridView彈出“屬性”,選擇AllowSorting為True即可。1:分頁保存選中狀態(tài)保存CheckBox的值
GridView在分頁過程中并不維護(hù)CheckBox的選擇狀態(tài),幸運(yùn)的是,我們可以使用Session來維護(hù)CheckBox的狀態(tài),這個(gè)功能使用RememberOldValues完成privatevoidRememberOldValues(){ArrayListcategoryIDList=newArrayList();intindex=-1;foreach(GridViewRowrowinokZMGV.Rows){index=Convert.ToInt32(okZMGV.DataKeys[row.RowIndex].Value);boolresult=((CheckBox)row.FindControl("IsCheckBox")).Checked;
//CheckintheSessionif(Session["state"]!=null)categoryIDList=(ArrayList)Session["state"];if(result){if(!categoryIDList.Contains(index))categoryIDList.Add(index);}elsecategoryIDList.Remove(index);}if(categoryIDList!=null&&categoryIDList.Count>0)Session["state"]=categoryIDList;}還原CheckBox的狀態(tài)
下一步,需要定義一個(gè)方法來還原Checkbox的狀態(tài)值
privatevoidRePopulateValues(){ArrayListcategoryIDList=(ArrayList)Session["state"];if(categoryIDList!=null&&categoryIDList.Count>0){foreach(GridViewRowrowinokZMGV.Rows){intindex=(int)okZMGV.DataKeys[row.RowIndex].Value;if(categoryIDList.Contains(index)){CheckBoxmyCheckBox=(CheckBox)row.FindControl("IsCheckBox");myCheckBox.Checked=true;}}}}
最后,在分頁事件里調(diào)用上面兩個(gè)方法protectedvoidpage_Click(objectsender,ImageClickEventArgse){RememberOldValues();stringcount=((ImageButton)sender).CommandArgument.ToString().ToLower();switch(count){case"prev":if(okZMGV.PageIndex>0){okZMGV.PageIndex-=1;}break;case"next":if(okZMGV.PageIndex<okZMGV.PageCount-1){okZMGV.PageIndex+=1;}break;case"0":okZMGV.PageIndex=0;break;case"last":okZMGV.PageIndex=okZMGV.pagecount-1;break;
}BrndOKBind();RePopulateValues();}
2.GridView選中,編輯,取消,刪除:效果圖:
后臺代碼:
你可以使用sqlhelper,本文沒用。代碼如下:
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
usingSystem.Data.SqlClient;publicpartialclass_Default:System.Web.UI.Page
{//清清月兒HYPERLINK
SqlConnectionsqlcon;
SqlCommandsqlcom;
stringstrCon="DataSource=(local);Database=數(shù)據(jù)庫名;Uid=帳號;Pwd=密碼";
protectedvoidPage_Load(objectsender,EventArgse)
{
if(!IsPostBack)
{
bind();
}
}
protectedvoidGridView1_RowEditing(objectsender,GridViewEditEventArgse)
{
GridView1.EditIndex=e.NewEditIndex;
bind();
}//刪除
protectedvoidGridView1_RowDeleting(objectsender,GridViewDeleteEventArgse)
{
stringsqlstr="deletefrom
表whereid=''"+GridView1.DataKeys[e.RowIndex].Value.ToString()+"''";
sqlcon=newSqlConnection(strCon);
sqlcom=newSqlCommand(sqlstr,sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
bind();
}//更新
protectedvoidGridView1_RowUpdating(objectsender,GridViewUpdateEventArgse)
{
sqlcon=newSqlConnection(strCon);
stringsqlstr="update表set字段1=''"
+((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim()+"'',字段2=''"
+((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim()+"'',字段3=''"
+((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim()+"''whereid=''"
+GridView1.DataKeys[e.RowIndex].Value.ToString()+"''";
sqlcom=newSqlCommand(sqlstr,sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
GridView1.EditIndex=-1;
bind();
}//取消
protectedvoidGridView1_RowCancelingEdit(objectsender,GridViewCancelEditEventArgse)
{
GridView1.EditIndex=-1;
bind();
}//綁定
publicvoidbind()
{
stringsqlstr="select*from表";
sqlcon=newSqlConnection(strCon);
SqlDataAdaptermyda=newSqlDataAdapter(sqlstr,sqlcon);
DataSetmyds=newDataSet();
sqlcon.Open();
myda.Fill(myds,"表");
GridView1.DataSource=myds;
GridView1.DataKeyNames=newstring[]{"id"};//主鍵
GridView1.DataBind();
sqlcon.Close();
}
}
前臺主要代碼:
......
<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"CellPadding="4"
ForeColor="#333333"GridLines="None"OnRowDeleting="GridView1_RowDeleting"OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating"OnRowCancelingEdit="GridView1_RowCancelingEdit">
<FooterStyleBackColor="#990000"Font-Bold="True"ForeColor="White"/>
<Columns>
<asp:BoundFieldDataField="身份證號碼"HeaderText="用戶ID"ReadOnly="True"/>
<asp:BoundFieldDataField="姓名"HeaderText="用戶姓名"/>
<asp:BoundFieldDataField="員工性別"HeaderText="性別"/>
<asp:BoundFieldDataField="家庭住址"HeaderText="家庭住址"/>
<asp:CommandFieldHeaderText="選擇"ShowSelectButton="True"/>
<asp:CommandFieldHeaderText="編輯"ShowEditButton="True"/>
<asp:CommandFieldHeaderText="刪除"ShowDeleteButton="True"/>
</Columns>
<RowStyleForeColor="#000066"/>
<SelectedRowStyleBackColor="#669999"Font-Bold="True"ForeColor="White"/>
<PagerStyleBackColor="White"ForeColor="#000066"HorizontalAlign="Left"/>
<HeaderStyleBackColor="#006699"Font-Bold="True"ForeColor="White"/>
</asp:GridView>
3.GridView正反雙向排序:
效果圖:點(diǎn)姓名各2次的排序,點(diǎn)其他也一樣可以。
后臺代碼:
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Collections;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
usingSystem.Data.SqlClient;
publicpartialclassDefault3:System.Web.UI.Page
{//清清月兒的博客HYPERLINK
SqlConnectionsqlcon;
stringstrCon="DataSource=(local);Database=北風(fēng)貿(mào)易;Uid=sa;Pwd=";
protectedvoidPage_Load(objectsender,EventArgse)
{
if(!IsPostBack)
{
ViewState["SortOrder"]="身份證號碼";
ViewState["OrderDire"]="ASC";
bind();
}
}
protectedvoidGridView1_Sorting(objectsender,GridViewSortEventArgse)
{
stringsPage=e.SortExpression;
if(ViewState["SortOrder"].ToString()==sPage)
{
if(ViewState["OrderDire"].ToString()=="Desc")
ViewState["OrderDire"]="ASC";
else
ViewState["OrderDire"]="Desc";
}
else
{
ViewState["SortOrder"]=e.SortExpression;
}
bind();
}
publicvoidbind()
{
stringsqlstr="selecttop5*from飛狐工作室";
sqlcon=newSqlConnection(strCon);
SqlDataAdaptermyda=newSqlDataAdapter(sqlstr,sqlcon);
DataSetmyds=newDataSet();
sqlcon.Open();
myda.Fill(myds,"飛狐工作室");
DataViewview=myds.Tables["飛狐工作室"].DefaultView;
stringsort=(string)ViewState["SortOrder"]+""+(string)ViewState["OrderDire"];
view.Sort=sort;
GridView1.DataSource=view;
GridView1.DataBind();
sqlcon.Close();
}
}前臺主要代碼:
<asp:GridViewID="GridView1"runat="server"AllowSorting="True"AutoGenerateColumns="False"
CellPadding="3"Font-Size="9pt"OnSorting="GridView1_Sorting"BackColor="White"BorderColor="#CCCCCC"BorderStyle="None"BorderWidth="1px">
<FooterStyleBackColor="White"ForeColor="#000066"/>
<Columns>
<asp:BoundFieldDataField="身份證號碼"HeaderText="用戶ID"SortExpression="身份證號碼"/>
<asp:BoundFieldDataField="姓名"HeaderText="用戶姓名"SortExpression="姓名"/>
<asp:BoundFieldDataField="員工性別"HeaderText="性別"SortExpression="員工性別"/>
<asp:BoundFieldDataField="家庭住址"HeaderText="家庭住址"SortExpression="家庭住址"/>
</Columns>
<RowStyleForeColor="#000066"/>
<SelectedRowStyleBackColor="#669999"Font-Bold="True"ForeColor="White"/>
<PagerStyleBackColor="White"ForeColor="#000066"HorizontalAlign="Left"/>
<HeaderStyleBackColor="#006699"Font-Bold="True"ForeColor="White"/>
</asp:GridView>
4.GridView和下拉菜單DropDownList結(jié)合:效果圖:
后臺代碼:
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Collections;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
usingSystem.Data.SqlClient;
publicpartialclassDefault4:System.Web.UI.Page
{
SqlConnectionsqlcon;
stringstrCon="DataSource=(local);Database=北風(fēng)貿(mào)易;Uid=sa;Pwd=sa";
protectedvoidPage_Load(objectsender,EventArgse)
{
DropDownListddl;
if(!IsPostBack)
{
stringsqlstr="selecttop5*from飛狐工作室";
sqlcon=newSqlConnection(strCon);
SqlDataAdaptermyda=newSqlDataAdapter(sqlstr,sqlcon);
DataSetmyds=newDataSet();
sqlcon.Open();
myda.Fill(myds,"飛狐工作室");
GridView1.DataSource=myds;
GridView1.DataBind();
for(inti=0;i<=GridView1.Rows.Count-1;i++)
{
DataRowViewmydrv=myds.Tables["飛狐工作室"].DefaultView[i];
if(Convert.ToString(mydrv["員工性別"]).Trim()=="True")
{
ddl=(DropDownList)GridView1.Rows[i].FindControl("DropDownList1");
ddl.SelectedIndex=0;
}
if(Convert.ToString(mydrv["員工性別"]).Trim()=="False")
{
ddl=(DropDownList)GridView1.Rows[i].FindControl("DropDownList1");
ddl.SelectedIndex=1;
}
}
sqlcon.Close();
}
}
publicSqlDataReaderddlbind()
{
stringsqlstr="selectdistinct員工性別from飛狐工作室";
sqlcon=newSqlConnection(strCon);
SqlCommandsqlcom=newSqlCommand(sqlstr,sqlcon);
sqlcon.Open();
returnsqlcom.ExecuteReader();
}前臺主要代碼:
<asp:GridViewID="GridView1"runat="server"AllowSorting="True"AutoGenerateColumns="False"
CellPadding="3"Font-Size="9pt"
BackColor="White"BorderColor="#CCCCCC"BorderStyle="None"BorderWidth="1px">
<FooterStyleBackColor="White"ForeColor="#000066"/>
<Columns>
<asp:BoundFieldDataField="身份證號碼"HeaderText="用戶ID"SortExpression="身份證號碼"/>
<asp:BoundFieldDataField="姓名"HeaderText="用戶姓名"SortExpression="姓名"/>
<asp:TemplateFieldHeaderText="員工性別">
<ItemTemplate>
<asp:DropDownListID="DropDownList1"runat="server"DataSource=''<%#ddlbind()%>''DataValueField="員工性別"DataTextField="員工性別">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundFieldDataField="家庭住址"HeaderText="家庭住址"SortExpression="家庭住址"/>
</Columns>
<RowStyleForeColor="#000066"/>
<SelectedRowStyleBackColor="#669999"Font-Bold="True"ForeColor="White"/>
<PagerStyleBackColor="White"ForeColor="#000066"HorizontalAlign="Left"/>
<HeaderStyleBackColor="#006699"Font-Bold="True"ForeColor="White"/>
</asp:GridView>5.GridView和CheckBox結(jié)合:效果圖:
后臺代碼:usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
usingSystem.Data.SqlClient;publicpartialclassDefault5:System.Web.UI.Page
{
//清清月兒HYPERLINK
SqlConnectionsqlcon;
stringstrCon="DataSource=(local);Database=北風(fēng)貿(mào)易;Uid=sa;Pwd=sa";
protectedvoidPage_Load(objectsender,EventArgse)
{
if(!IsPostBack)
{
bind();
}
}
protectedvoidCheckBox2_CheckedChanged(objectsender,EventArgse)
{
for(inti=0;i<=GridView1.Rows.Count-1;i++)
{
CheckBoxcbox=(CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if(CheckBox2.Checked==true)
{
cbox.Checked=true;
}
else
{
cbox.Checked=false;
}
}
}
protectedvoidButton2_Click(objectsender,EventArgse)
{
sqlcon=newSqlConnection(strCon);
SqlCommandsqlcom;
for(inti=0;i<=GridView1.Rows.Count-1;i++)
{
CheckBoxcbox=(CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if(cbox.Checked==true)
{
stringsqlstr="deletefrom飛狐工作室where身份證號碼=''"+GridView1.DataKeys[i].Value+"''";
sqlcom=newSqlCommand(sqlstr,sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
}
}
bind();
}
protectedvoidButton1_Click(objectsender,EventArgse)
{
CheckBox2.Checked=false;
for(inti=0;i<=GridView1.Rows.Count-1;i++)
{
CheckBoxcbox=(CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
cbox.Checked=false;
}
}
publicvoidbind()
{
stringsqlstr="selecttop5*from飛狐工作室";
sqlcon=newSqlConnection(strCon);
SqlDataAdaptermyda=newSqlDataAdapter(sqlstr,sqlcon);
DataSetmyds=newDataSet();
sqlcon.Open();
myda.Fill(myds,"tb_Member");
GridView1.DataSource=myds;
GridView1.DataKeyNames=newstring[]{"身份證號碼"};
GridView1.DataBind();
sqlcon.Close();
}
}前臺主要代碼:<asp:GridViewID="GridView1"runat="server"AllowSorting="True"AutoGenerateColumns="False"
CellPadding="3"Font-Size="9pt"
BackColor="White"BorderColor="#CCCCCC"BorderStyle="None"BorderWidth="1px">
<FooterStyleBackColor="White"ForeColor="#000066"/>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBoxID="CheckBox1"runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundFieldDataField="身份證號碼"HeaderText="用戶ID"SortExpression="身份證號碼"/>
<asp:BoundFieldDataField="姓名"HeaderText="用戶姓名"SortExpression="姓名"/>
<asp:BoundFieldDataField="家庭住址"HeaderText="家庭住址"SortExpression="家庭住址"/>
</Columns>
<RowStyleForeColor="#000066"/>
<SelectedRowStyleBackColor="#669999"Font-Bold="True"ForeColor="White"/>
<PagerStyleBackColor="White"ForeColor="#000066"HorizontalAlign="Left"/>
<HeaderStyleBackColor="#006699"Font-Bold="True"ForeColor="White"/>
</asp:GridView>
<asp:CheckBoxID="CheckBox2"runat="server"AutoPostBack="True"Font-Size="9pt"OnCheckedChanged="CheckBox2_CheckedChanged"
Text="全選"/>
<asp:ButtonID="Button1"runat="server"Font-Size="9pt"Text="取消"OnClick="Button1_Click"/>
<asp:ButtonID="Button2"runat="server"Font-Size="9pt"Text="刪除"OnClick="Button2_Click"/>6.鼠標(biāo)移到GridView某一行時(shí)改變該行的背景色方法一:效果圖:
做法:
雙擊GridView的OnRowDataBound事件;
在后臺的GridView1_RowDataBound()方法添加代碼,最后代碼如下所示:
protectedvoidGridView1_RowDataBound(objectsender,GridViewRowEventArgse)
{
inti;
//執(zhí)行循環(huán),保證每條數(shù)據(jù)都可以更新
for(i=0;i<GridView1.Rows.Count;i++)
{
//首先判斷是否是數(shù)據(jù)行
if(e.Row.RowType==DataControlRowType.DataRow)
{
//當(dāng)鼠標(biāo)停留時(shí)更改背景色
e.Row.Attributes.Add("onmouseover","c=this.style.backgroundColor;this.style.backgroundColor=''#00A9FF''");
//當(dāng)鼠標(biāo)移開時(shí)還原背景色
e.Row.Attributes.Add("onmouseout","this.style.backgroundColor=c");
}
}
}前臺代碼:
<htmlxmlns="HYPERLINK">
<headrunat="server">
<title>實(shí)現(xiàn)鼠標(biāo)劃過改變GridView的行背景色清清月兒HYPERLINK
</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"DataKeyNames="身份證號碼"
DataSourceID="SqlDataSource1"AllowSorting="True"BackColor="White"BorderColor="#CCCCCC"BorderStyle="None"BorderWidth="1px"CellPadding="3"Font-Size="12px"OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundFieldDataField="身份證號碼"HeaderText="身份證號碼"ReadOnly="True"SortExpression="身份證號碼"/>
<asp:BoundFieldDataField="姓名"HeaderText="姓名"SortExpression="姓名"/>
<asp:BoundFieldDataField="家庭住址"HeaderText="家庭住址"SortExpression="家庭住址"/>
<asp:BoundFieldDataField="郵政編碼"HeaderText="郵政編碼"SortExpression="郵政編碼"/>
</Columns>
<FooterStyleBackColor="White"ForeColor="#000066"/>
<RowStyleForeColor="#000066"/>
<SelectedRowStyleBackColor="#669999"Font-Bold="True"ForeColor="White"/>
<PagerStyleBackColor="White"ForeColor="#000066"HorizontalAlign="Left"/>
<HeaderStyleBackColor="#006699"Font-Bold="True"ForeColor="White"/>
</asp:GridView>
<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ConnectionStrings:北風(fēng)貿(mào)易ConnectionString1%>"
SelectCommand="SELECTtop5[身份證號碼],[姓名],[員工性別],[家庭住址],[郵政編碼]FROM[飛狐工作室]"DataSourceMode="DataReader"></asp:SqlDataSource>
</div>
</form>
</body>
</html>7.鼠標(biāo)移到GridView某一行時(shí)改變該行的背景色方法二:效果圖:
做法:和上面的一樣就是代碼不同
protectedvoidGridView1_RowDataBound(objectsender,GridViewRowEventArgse)
{
//inti;
////執(zhí)行循環(huán),保證每條數(shù)據(jù)都可以更新
//for(i=0;i<GridView1.Rows.Count;i++)
//{
//
//首先判斷是否是數(shù)據(jù)行
//
if(e.Row.RowType==DataControlRowType.DataRow)
//
{
//
//當(dāng)鼠標(biāo)停留時(shí)更改背景色
//
e.Row.Attributes.Add("onmouseover","c=this.style.backgroundColor;this.style.backgroundColor=''#00A9FF''");
//
//當(dāng)鼠標(biāo)移開時(shí)還原背景色
//
e.Row.Attributes.Add("onmouseout","this.style.backgroundColor=c");
//
}
//}
//如果是綁定數(shù)據(jù)行
if(e.Row.RowType==DataControlRowType.DataRow)
{
//鼠標(biāo)經(jīng)過時(shí),行背景色變
e.Row.Attributes.Add("onmouseover","this.style.backgroundColor=''#E6F5FA''");
//鼠標(biāo)移出時(shí),行背景色變
e.Row.Attributes.Add("onmouseout","this.style.backgroundColor=''#FFFFFF''");
}
}8.GridView實(shí)現(xiàn)刪除時(shí)彈出確認(rèn)對話框:效果圖:
實(shí)現(xiàn)方法:
雙擊GridView的OnRowDataBound事件;
在后臺的GridView1_RowDataBound()方法添加代碼,最后代碼如下所示:
protectedvoidGridView1_RowDataBound(objectsender,GridViewRowEventArgse)
{
//如果是綁定數(shù)據(jù)行
if(e.Row.RowType==DataControlRowType.DataRow)
{
if(e.Row.RowState==DataControlRowState.Normal||e.Row.RowState==DataControlRowState.Alternate)
{
((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick","javascript:returnconfirm(''你確認(rèn)要?jiǎng)h除:\""+e.Row.Cells[1].Text+"\"嗎?'')");
}
}
}9.GridView實(shí)現(xiàn)自動(dòng)編號:效果圖:
實(shí)現(xiàn)方法:
雙擊GridView的OnRowDataBound事件;
在后臺的GridView1_RowDataBound()方法添加代碼,最后代碼如下所示:
protectedvoidGridView1_RowDataBound(objectsender,GridViewRowEventArgse)
{
//如果是綁定數(shù)據(jù)行//清清月兒HYPERLINK
if(e.Row.RowType==DataControlRowType.DataRow)
{
////鼠標(biāo)經(jīng)過時(shí),行背景色變
//e.Row.Attributes.Add("onmouseover","this.style.backgroundColor=''#E6F5FA''");
////鼠標(biāo)移出時(shí),行背景色變
//e.Row.Attributes.Add("onmouseout","this.style.backgroundColor=''#FFFFFF''");
////當(dāng)有編輯列時(shí),避免出錯(cuò),要加的RowState判斷
//if(e.Row.RowState==DataControlRowState.Normal||e.Row.RowState==DataControlRowState.Alternate)
//{
//
((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick","javascript:returnconfirm(''你確認(rèn)要?jiǎng)h除:\""+e.Row.Cells[1].Text+"\"嗎?'')");
//}
}
if(e.Row.RowIndex!=-1)
{
intid=e.Row.RowIndex+1;
e.Row.Cells[0].Text=id.ToString();
}
}
注意這時(shí)最好把前臺的第一列的表頭該為“編號”,因?yàn)橐郧暗牡谝涣斜弧俺缘簟绷恕?/p>
<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"CellPadding="3"OnRowDeleting="GridView1_RowDeleting"OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating"OnRowCancelingEdit="GridView1_RowCancelingEdit"BackColor="White"BorderColor="#CCCCCC"BorderStyle="None"BorderWidth="1px"Font-Size="12px"OnRowDataBound="GridView1_RowDataBound">
<FooterStyleBackColor="White"ForeColor="#000066"/>
<Columns>
<asp:BoundFieldDataField="身份證號碼"HeaderText="編號"ReadOnly="True"/>
<asp:BoundFieldDataField="姓名"HeaderText="用戶姓名"/>
<asp:BoundFieldDataField="員工性別"HeaderText="性別"/>
<asp:BoundFieldDataField="家庭住址"HeaderText="家庭住址"/>
<asp:CommandFieldHeaderText="選擇"ShowSelectButton="True"/>
<asp:CommandFieldHeaderText="編輯"ShowEditButton="True"/>
<asp:CommandFieldHeaderText="刪除"ShowDeleteButton="True"/>
</Columns>
<RowStyleForeColor="#000066"/>
<SelectedRowStyleBackColor="#669999"Font-Bold="True"ForeColor="White"/>
<PagerStyleBackColor="White"ForeColor="#000066"HorizontalAlign="Left"/>
<HeaderStyleBackColor="#006699"Font-Bold="True"ForeColor="White"/>
</asp:GridView>10.GridView實(shí)現(xiàn)自定義時(shí)間貨幣等字符串格式:效果圖:
圖1-未格式化前
圖2-格式化后
解決方法:
在2.0中,如果要在綁定列中顯示比如日期格式等,如果用下面的方法是顯示不了的<asp:BoundFieldDataField="CreationDate"
DataFormatString="{0:M-dd-yyyy}"
HeaderText="C
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 統(tǒng)編版三年級語文下冊第五單元測試卷(A)(含答案)
- 政府資金補(bǔ)助協(xié)議
- 長沙二手房交易合同示例
- 中英俄煤炭購銷合同范本
- 江蘇省連云港市東海縣晶都雙語學(xué)校九年級化學(xué)上冊 6.2 二氧化碳制取的研究教學(xué)設(shè)計(jì) 新人教版
- 高中歷史 第六單元 近代歐美資產(chǎn)階級的代議制 第19課 美國的聯(lián)邦制教學(xué)設(shè)計(jì) 北師大版必修1
- 二手房購買定金合同樣本
- 2025聯(lián)合經(jīng)營合同
- 商品房買賣合同
- 2025年度光伏發(fā)電系統(tǒng)施工及運(yùn)維合同
- 喘病中醫(yī)護(hù)理常規(guī)
- 2025屆陜西省高考適應(yīng)性檢測(三)數(shù)學(xué)試題+答案
- 山東省高中名校2025屆高三4月校際聯(lián)合檢測大聯(lián)考物理試題及答案
- 大型活動(dòng)籌備的總體進(jìn)度計(jì)劃
- 農(nóng)田土壤污染的治理技術(shù)分析試題及答案
- 醫(yī)療機(jī)構(gòu)抗菌藥物臨床應(yīng)用分級管理目錄(2024年版)
- 【MOOC】跨文化交際入門-華中師范大學(xué) 中國大學(xué)慕課MOOC答案
- 心房顫動(dòng)診斷和治療中國指南(2023) 解讀
- 建筑施工特種作業(yè)人員體檢表
- 復(fù)變函數(shù)與積分變換第三章復(fù)變函數(shù)的積分
- (完整版)機(jī)械設(shè)計(jì)基礎(chǔ)知識點(diǎn)詳解
評論
0/150
提交評論