asp.net中我想让girdview中的一列显示特定的长度和分页
我有个girdview我想让第四列就显示30个字符长度如果长的话就用"..."表示我会实现这个功能。。可是我再加个分页功能后就报错(指定的参数超出有效值的范围)。。不知道...
我有个girdview我想让第四列就显示30个字符长度如果长的话就用"..."表示我会实现这个功能。。可是我再加个分页功能后就报错(指定的参数超出有效值的范围)。。不知道怎么解决。!!代码如下。希望哪位大哥教教小弟我。
//页面代码
<asp:GridView ID="gvnews" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical"
Height="198px" Width="728px" AllowPaging="True" OnPageIndexChanged="gvnews_PageIndexChanged" OnPageIndexChanging="gvnews_PageIndexChanging" OnRowDataBound="gvnews_RowDataBound" PageSize="4">
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<Columns>
<asp:BoundField DataField="messID" HeaderText="编号" />
<asp:BoundField DataField="messTypeName" HeaderText="类别" />
<asp:BoundField DataField="messTitle" HeaderText="题目" />
<asp:BoundField DataField="messBody" HeaderText="内容" AccessibleHeaderText="messBody" />
<asp:BoundField DataField="MessDate" HeaderText="时间" />
<asp:BoundField DataField="Author" HeaderText="作者" />
<asp:ImageField DataImageUrlField="messimg" HeaderText="图片">
<ControlStyle Height="30px" Width="30px" />
</asp:ImageField>
</Columns>
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="DarkGray" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="LightBlue" />
</asp:GridView>
//cs代码
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bussiness.BmanageNews bmn = new BmanageNews();
this.gvnews.DataSource = bmn.selectnews();
this.DataBind();
}
}
protected void gvnews_RowDataBound(object sender, GridViewRowEventArgs e)
{
String body = e.Row.Cells[3].Text;
if (body.Length > 30)
{
body = body.Substring(0,30) + "...";
}
e.Row.Cells[3].Text = body;
}
protected void gvnews_PageIndexChanged(object sender, EventArgs e)
{
Bussiness.BmanageNews bmn = new BmanageNews();
this.gvnews.DataSource = bmn.selectnews();
this.DataBind();
}
protected void gvnews_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.gvnews.PageIndex = e.NewPageIndex;
this.DataBind();
} 展开
//页面代码
<asp:GridView ID="gvnews" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical"
Height="198px" Width="728px" AllowPaging="True" OnPageIndexChanged="gvnews_PageIndexChanged" OnPageIndexChanging="gvnews_PageIndexChanging" OnRowDataBound="gvnews_RowDataBound" PageSize="4">
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<Columns>
<asp:BoundField DataField="messID" HeaderText="编号" />
<asp:BoundField DataField="messTypeName" HeaderText="类别" />
<asp:BoundField DataField="messTitle" HeaderText="题目" />
<asp:BoundField DataField="messBody" HeaderText="内容" AccessibleHeaderText="messBody" />
<asp:BoundField DataField="MessDate" HeaderText="时间" />
<asp:BoundField DataField="Author" HeaderText="作者" />
<asp:ImageField DataImageUrlField="messimg" HeaderText="图片">
<ControlStyle Height="30px" Width="30px" />
</asp:ImageField>
</Columns>
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="DarkGray" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="LightBlue" />
</asp:GridView>
//cs代码
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bussiness.BmanageNews bmn = new BmanageNews();
this.gvnews.DataSource = bmn.selectnews();
this.DataBind();
}
}
protected void gvnews_RowDataBound(object sender, GridViewRowEventArgs e)
{
String body = e.Row.Cells[3].Text;
if (body.Length > 30)
{
body = body.Substring(0,30) + "...";
}
e.Row.Cells[3].Text = body;
}
protected void gvnews_PageIndexChanged(object sender, EventArgs e)
{
Bussiness.BmanageNews bmn = new BmanageNews();
this.gvnews.DataSource = bmn.selectnews();
this.DataBind();
}
protected void gvnews_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.gvnews.PageIndex = e.NewPageIndex;
this.DataBind();
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询