標籤:style c tar ext a width
1:資料繫結
GridView 支援資料繫結的資料來源格式比較多,例如可以使用ObjectDataSource綁定資料來源,
Dataset,datatable,List<T>等
2:資料行繫結
1)BoundField--一般直接綁定資料來源對應的欄位,通過指定DataField來實現綁定。
2)CheckBoxField--當GridView控制項需要展示CheckBox控制項時使用,也是通過DataField綁定一個bool類型的欄位即可。
3)HyperLinkFied--綁定的列實現超連結功能,DataNavigateUrlFields="ID" DataNavigateUrlFormatString="XXX.aspx?ID{0}"
4)ImageField,
5)ButtonField,
6)CommandField--命令列列模板,內建增刪改查,選擇等功能(沒有具體使用)
7)TemplateField --比較靈活,一般通過編輯列模板可以實現我們需要的功能。
3:GridView -OnRowDataBound事件
通過該事件我們可以為綁定的列指定事件等一系列操作
protected void FSLGridView1_RowDataBounding(object sender, GridViewRowEventArgs e)
{ if (e.Row.RowType == DataControlRowType.DataRow)
{
System.Data.DataRowView dv = (System.Data.DataRowView)e.Row.DataItem;
string ID = dv["ID"].ToString();
Button btnCheck = (Button)e.Row.FindControl("BtnCheck");
Button btnLook = (Button)e.Row.FindControl("BtnLook");
btnCheck.Attributes.Add("onclick", "changevalue(‘" + btnCheck.ClientID + "‘,‘" + ID + "‘);return false");
}
}
4:GridView -OnRowCommand事件
當我們為模板列裡面的控制項指定CommandName="linkDel" CommandArgument=‘<%#Eval("ID") %>‘等參數時,
我們操作這些控制項時就會觸發該事件。 protected void FSLGridView2_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "linkDel")
{
if (e.CommandArgument == null)
{
return;
}
string ID = e.CommandArgument.ToString();
EvaluateDataBLL bll = new EvaluateDataBLL();
if (bll.DeleteRowDataByID(ID))
{
Framework.Assistant.Web.ClientScriptHelper.WriteAlert("success", "刪除成功!");
Framework.Assistant.Web.ClientScriptHelper.RegisterScript("Close", "CloseWindow(true);");
}
else
{
Framework.Assistant.Web.ClientScriptHelper.WriteAlert("Failure", "刪除失敗,請校正後重新操作!");
}
}
}
5:GirdView控制項的遍曆
foreach (GridViewRow item in this.FSLGridView1.Rows)
{
//TODO:The Things you want to DO
}
6:列的格式化展示
<asp:TemplateField HeaderText="內容
<ItemStyle Width="15%" HorizontalAlign="Center" />
<ItemTemplate>
<%# DecryptinfoContent(Eval("infoContent").ToString())%>
</ItemTemplate>
</asp:TemplateField>
DecryptinfoContent--頁面後台方法