您的位置:首页 > 编程语言 > ASP

asp.net后台对sql语句排序,筛选,gridview隐藏过长的字符串鼠标放上去显示全部,dropdownlist在前台显示拼接字符串

2011-06-11 10:03 686 查看
1.排序

datatable dtSJList=赋值;
DataView dv = new DataView(dtSJList);
dv.Sort = "souaddtime desc";//按时间进行倒序排序
dtSJList = dv.ToTable();

2.筛选

datatable的Select方法

例如:

//进行模糊查找
protected void btnSearch_Click(object sender, ImageClickEventArgs e)
{
this.AspNetPager1.Visible = true;
try
{
DataTable ds = service.GetBusinessNames(officeInfo.ofNote1, officeInfo.ofParentId, Convert.ToInt32(ddltype.SelectedValue));
DataTable dt_New = null;

DataRow[] dr = null;
if (ds.Rows.Count > 0)
{

dt_New = ds.Clone();
if (txtName.Text.Trim() == string.Empty)
{
dt_New = ds;

}
else
{
string strcondetion = @"业务名称 like '%" + txtName.Text.ToString().Trim() + "%'";
dr = ds.Select(strcondetion);
if (dr.Length > 0)
{
for (int i = 0; i < dr.Length; i++)
{
dt_New.ImportRow(dr[i]);
}

}
else
{
this.AspNetPager1.Visible = false;
}

}
int sumcount = 0;

sumcount = dt_New.Rows.Count;
PagedDataSource pds = new PagedDataSource();
AspNetPager1.RecordCount = sumcount;
pds.AllowPaging = true;
pds.PageSize = AspNetPager1.PageSize;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
pds.DataSource = dt_New.DefaultView;

gvBusiness.DataSource = dt_New;
gvBusiness.DataBind();

this.AspNetPager1.CustomInfoHTML = string.Format("当前第{0}/{1}页 共{2}条记录 每页{3}条", new object[] { this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageCount, this.AspNetPager1.RecordCount, this.AspNetPager1.PageSize });

}
else
{
this.AspNetPager1.Visible = false;
}

}
catch
{
this.AspNetPager1.Visible = false;
}
}


3. gridview隐藏过长的字符串鼠标放上去显示全部,使用gridview的DataBound事件


//隐藏过长的列
protected void gvBusiness_DataBound(object sender, EventArgs e)
{
// 演示ToolTip,使用GridView自带的ToolTip
for (int i = 0; i <gvBusiness.Rows.Count; i++)
{
gvBusiness.Rows[i].Cells[2].ToolTip = gvBusiness.Rows[i].Cells[2].Text;
if (gvBusiness.Rows[i].Cells[2].Text.Length > 22)
gvBusiness.Rows[i].Cells[2].Text = gvBusiness.Rows[i].Cells[2].Text.Substring(0,22) + "...";
}
}

或者直接写调用方法

/// <summary>

/// 隐藏过长的数据

/// </summary>

/// <param name="gridView">要隐藏的GridView对象</param>

/// <param name="number">隐藏的开始位</param>

public static  void gridViewTooling(GridView gridView ,int number)
{

//隐藏过长的数据

for (int j = 0; j < gridView.Columns.Count; j++)

{

for (int i = 0; i < gridView.Rows.Count; i++)

{

gridView.Rows[i].Cells[j].ToolTip = gridView.Rows[i].Cells[j].Text;

if (gridView.Rows[i].Cells[j].Text.Length > number)
{

gridView.Rows[i].Cells[j].Text = gridView.Rows[i].Cells[j].Text.Substring(0, number) + "...";

}

}

}

}


4.dropdownlist在前台显示拼接字符串
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐