<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound1" CellPadding="4" ForeColor="#333333" GridLines="Horizontal" AllowPaging="True" PageSize="9" Width="100%"> <FooterStyle BackColor="#DBE7F6" ForeColor="black" /> <Columns> <asp:BoundField HeaderText="" FooterStyle-Width="20px"></asp:BoundField> <asp:TemplateField HeaderText="我要留言" HeaderStyle-Font-Size="16"> <ItemTemplate> <table width="100%"> <tr> <td style="text-align: center;"> <asp:Label ID="libTitle" runat="server" Style="position: relative" Text='<%# eval_r("Title") %>'></asp:Label> </td> </tr> <tr> <td style="text-align: left;"> <asp:Label ID="libContent" runat="server" Style="position: relative" Text='<%# eval_r("Content") %>'></asp:Label> </td> </tr> <tr> <td style="text-align: right;"> <asp:Label ID="libAuthor" runat="server" Style="position: relative" Text='<%# eval_r("ToName") %>'></asp:Label> <asp:Label ID="libCreated" runat="server" Style="position: relative" Text='<%# eval_r("Created") %>'></asp:Label> </td> </tr> </table> </ItemTemplate> </asp:TemplateField> </Columns> <RowStyle BackColor="#EFF3FB" /> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <HeaderStyle BackColor="#00A0DB" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#2461BF" /> <AlternatingRowStyle BackColor="White" /> <PagerSettings Visible="False" /> </asp:GridView> public void GridView1Show() { SPList list = null; try { list = SPContext.Current.Web.Lists["Messageboard"]; } catch (Exception err) { // Label lable = this.GridView1.FooterRow.FindControl("libMessage") as Label; libMessage.Text = "当前网站中没有留言板列表,请联系管理员创建.出错详细信息:" + err.Message; } SPQuery query = new SPQuery(); query.Query = @"<Where><Eq><FieldRef Name='Author' /><Value Type=\'Text\'>" + getme() + "</Value></Eq></Where><OrderBy><FieldRef Name='Created' Ascending='FALSE'></FieldRef></OrderBy>"; try { SPListItemCollection items = list.GetItems(query); if (items.Count < 1) { //Label lable = this.GridView1.FooterRow.FindControl("libMessage") as Label; libMessage.Text = "您没有给别人留言;或者您给别人的留言别人已读并且删除!"; btnFirst.Visible = false;//隐藏分页按钮 btnPrev.Visible = false; btnNext.Visible = false; btnLast.Visible = false; } else { GridView1.DataSource = CreateDataTable(); GridView1.DataBind(); } } catch (Exception err) { // Label lable = this.GridView1.FooterRow.FindControl("libMessage") as Label; libMessage.Text = "出现错误,请联系管理员.原因" + err.Message; } }
< asp:TemplateField HeaderText = " 流行程度 " >
< ItemTemplate >
ItemTemplate>
asp:TemplateField>
//后台方法:
protected string GetStatusPicture(object dataItem)
{
int units = Int32.Parse(DataBinder.eval_r(dataItem, "PopularLevel").ToString());
string strNum = "";
switch (units)
{
case 0:
strNum = "0 颗星";
break;
case 1:
strNum = "1 颗星";
break;
case 2:
strNum = "2 颗星";
break;
case 3:
strNum = "3 颗星";
break;
case 4:
strNum = "4 颗星";
break;
case 5:
strNum = "5 颗星";
break;
}
return strNum;
}
//说明:后台方法必须为Public或Proteced,接受的参数最好为Object类型,然后再方法内进行转换。