扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:华未眠 来源:CSDN 2008年3月25日
关键字: 控件 C1WebGrid ComponentOne Web开发 软件

<%
@ Register Assembly="C1.Web.C1WebGrid.2" Namespace="C1.Web.C1WebGrid" TagPrefix="C1WebGrid" %>
<c1webgrid:c1webgrid id="C1WGridResult" width="100%" runat="server" allowpaging="True" allowsorting="True" backcolor="White" bordercolor="#999999" borderstyle="Groove" borderwidth="1px" cellpadding="3" groupindent="" pagesize="30" allowcolsizing="True" imagesortascending="~/images/up.gif" imagesortdescending="~/images/down.gif" onpageindexchanging="C1WGridResult_PageIndexChanged" onsortingcommand="C1WGridResult_SortingCommand" onitemdatabound="C1WGridResult_ItemDataBound" onitemcreated="C1WGridResult_ItemCreated">
<footerstyle backcolor="#CCCCCC" font-size="9pt" font-bold="False" font-italic="False" font-overline="False"
font-strikeout="False" font-underline="False" forecolor="Black" />
<selecteditemstyle backcolor="White" font-bold="False" font-italic="False" font-overline="False"
font-strikeout="False" font-underline="False" forecolor="White" />
<itemstyle backcolor="WhiteSmoke" font-size="9pt" font-bold="False" font-italic="False" font-overline="False"
font-strikeout="False" font-underline="False" forecolor="Black" horizontalalign="Left" bordercolor="#E0E0E0" borderstyle="Dashed" borderwidth="1px" wrap="False" />
<groupingstyle backcolor="White" bordercolor="Silver" borderwidth="1px" wrap="False"></groupingstyle>
<pagerstyle backcolor="#DEDBDE" font-bold="False" font-italic="False" font-overline="False"
font-strikeout="False" font-underline="False" forecolor="Black" horizontalalign="Left" mode="NumericPages" borderstyle="Groove" borderwidth="1px" />
<headerstyle backcolor="#999999" font-size="9pt" height="25px" font-bold="True" font-italic="False" font-overline="False"
font-strikeout="False" font-underline="False" forecolor="Black" cssclass="C1WGridCss" wrap="False" />
<alternatingitemstyle backcolor="LightGray" font-bold="False" font-italic="False" font-overline="False"
font-strikeout="False" font-underline="False" bordercolor="#404040" borderstyle="Dotted" borderwidth="1px" />
</c1webgrid:c1webgrid>
protected void C1WGridResult_SortingCommand(object sender, C1.Web.C1WebGrid.C1SortingCommandEventArgs e)
{
//用来记录排序方式
String SortDirection = "ASC";
//用来记录排序表达式
String SortExpression = e.SortExpression.ToString();//得到当前选择排序的列的排序表达式
//如果为空则直接返回
if (SortExpression == "") return;
try
{
//如果不为null
if (C1WGridResult.Attributes["SortExpression"] != null)
{
if (SortExpression == C1WGridResult.Attributes["SortExpression"].ToString())
{
SortDirection = (C1WGridResult.Attributes["SortDirection"].ToString() == SortDirection ? "DESC" : "ASC");//选择相反的排序方式
}
}
else
{
SortDirection = "DESC";//
}
//将上面得到的值附给WebGrid,然后重新绑定数据
C1WGridResult.Attributes["SortExpression"] = SortExpression;
C1WGridResult.Attributes["SortDirection"] = SortDirection;
BindC1WGridResult();
}
catch (Exception ex)
{
}
}
//这里代码的目的是为了使不能排序的列,如模板列,的列
//头显示为文字形式而不是连接形式,因为在这个控件中,
//即使把列的SortExpression设置为空也还是会在列头处
//显示为一个linkbutton(和GridView不同)
protected void C1WGridResult_ItemCreated(object sender, C1.Web.C1WebGrid.C1ItemEventArgs e)
{
try
{
if (e.Item.ItemType == C1.Web.C1WebGrid.C1ListItemType.Header)
{
TableCellCollection tcc = e.Item.Cells;
//这里假设第一列为模板列
tcc.RemoveAt(0);
tcc.Add(new TableHeaderCell());
tcc[0].Text = "选择";//设置列头文字
}
}
catch
{ }
}
另外还可以通如下设置使相同内容的两个Cell合并
C1WGridResult.Columns[2].RowMerge = C1.Web.C1WebGrid.RowMergeEnum.Free;//合并相同
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。