(1)如何在DataGrid的PagerStyle行(显示页数的行)上显示查询出来的记录数?
(2)怎样将页面通过该页上的一个打印按钮来实现打印?
(2)怎样将页面通过该页上的一个打印按钮来实现打印?
解决方案 »
- 怎样获取DataGridViewTextBoxCell中的textbox?
- Request.QueryString的问题
- 关于黑冰防火墙
- asp.net删除数据,求救中
- 请教html中关于cookies的问题
- 小弟往sql数据库里的mydate列(smalldatetime)中添加date值=now()的时候,一切正常,但是使用这个值的时候才发现所有的mydate列中的所
- 一个关于js参数的问题
- asp:button的ToolTip文字可不可以换行显示
- c:\inetpub\wwwroot\WebApplication3\CrystalReport1.rpt 自定义工具“CrystalDecisions.VSDesigner.CodeGen.ReportCodeGenerator”失败
- 打开窗体????
- 打开本地ASP文件的怎么直接转换成HTM?
- 定时执行的问题
DataTable dtc=.....;
double rowcount=Convert.ToDouble(dtc.Rows.Count);
this.lblPageCount.Text="共 " +rowcount.ToString() +"条记录";2,
如何实现自定义及自动逐页打印DataGrid显示的内容
http://dev.csdn.net/develop/article/19/19353.shtm 在C#里实现DATAGRID的打印预览和打印
http://dev.csdn.net/develop/article/17/17851.shtm
-------
你可以这样:
this.dataGrid1.Controls[0].Controls[this.dataGrid1.Controls.Count-1].Cells[0].Text = 你的记录数;
If e.Item.ItemType = ListItemType.Pager Then
Dim pager As TableCell = CType(e.Item.Controls(0), TableCell)
Dim i As Integer
Dim o As Object
Dim l2 As New Label
pager.Controls.AddAt(0, l2) For i = 0 To pager.Controls.Count - 1
o = pager.Controls(i) If TypeOf o Is LinkButton Then
Dim h As LinkButton = CType(o, LinkButton)
'h.Text = "[" + h.Text + "]"
ElseIf TypeOf o Is Label Then
Dim l As Label = CType(o, Label)
'l.Text = "第" + l.Text + "页"
l2.Text = " 当前页为第 " + l.Text + " 页 " End If
Next End If
End Sub
2.DataTable dt = new DataTable();
...................//点表示数据绑定的代码
Label lb = (Label)this.dataGrid.Controls.FindControl("label");
lb.Text = dt.Rows.Count.ToString();
{
ListItemType lit=e.Item.ItemType;
if(lit==ListItemType.Footer)
{
TableCell tc1=e.Item.Cells[0];
TableCell tc2=e.Item.Cells[1];
Label L_xj=new Label();
L_xj.ID="lb_xj";
L_xj.Width=30;
L_xj.Text="行数";
tc1.Controls.Add(L_xj); Label L_SumData=new Label();
L_SumData.ID="L_SumData";
L_SumData.Width=30;
L_SumData.Text=赋值
tc2.Controls.Add(L_SumData);
}
}
void DataGrid1_ItemCreated(object sender, DataGridItemEventArgs e)
{
ListItemType lit=e.Item.ItemType;
if(lit==ListItemType.Pager){
TableCell tc1=e.Item.Cells[0]; Label L_xj=new Label();
L_xj.ID="lb_xj";
L_xj.Width=200;
L_xj.Text="(共有记录数:"+Recnum+" 条)";//Recnum是在BindGrid函数中得到的字符型变量
tc1.Controls.Add(L_xj);
}
}
请大侠们继续指教问题二: 通过点击本页上的打印按钮来打印该页,如何做?
http://dev.csdn.net/develop/article/17/17851.shtm
这个可以的,我试过了!
label控件,用于显示记录数
2.在DataGrid的ItemDataBound事件中加下面代码
if(e.Item.ItemType == ListItemType.Header) //假如你的导航条位置是在
//DataGrid的头部
{
Label lb = (Label)this.dataGrid.Controls.FindControl("label");
lb.Text = 5; //5表示显示的记录数,你可能从数据库中取得
}
1.在DataGrid的导航条上显示查询的记录数:
void DataGrid1_ItemCreated(object sender, DataGridItemEventArgs e)
{
ListItemType lit=e.Item.ItemType;
if(lit==ListItemType.Pager){
TableCell tc1=e.Item.Cells[0]; Label L_xj=new Label();
L_xj.ID="lb_xj";
L_xj.Width=200;
L_xj.Text="(共有"+Recnum+"条记录)";
tc1.Controls.Add(L_xj);
}
}Recnum 是窗体级全局变量,即:public string Recnum="";
在数据绑定函数里初始化Recnum变量,即:
void BindGrid()
{
string SortSQL=Session["SortSQL"].ToString();
string ConnectionString = "Provider=msdaora;user id=bgzdh;data source=zymis;password=bgzdh2005";
OleDbConnection myConnection = new OleDbConnection(ConnectionString);
OleDbDataAdapter DataAdapter = new OleDbDataAdapter(SortSQL, myConnection); DataSet ds = new DataSet();
DataAdapter.Fill(ds,"XC_DWTG");
SortString=DataGrid1.Attributes["SortString"];
SortDirection=DataGrid1.Attributes["SortDirection"];
DataView dv = ds.Tables["XC_DWTG"].DefaultView;
Recnum=ds.Tables["XC_DWTG"].Rows.Count.ToString(); //初始化Recnum
dv.Sort=SortString+" "+SortDirection; //指定视图的排序方式;
DataGrid1.DataSource = dv;
DataGrid1.DataBind();
}2.怎样将页面通过该页上的一个打印按钮来实现打印(但并不打印该按钮), 即:
void Page_Load(object sender, EventArgs e) {
this.Button1.Attributes.Add("onclick","history.back();return false;");//该窗体上的返回按钮,其作用是将该页回滚页到上一个视图(相当于IE工具栏上的后退按钮)。
this.Button2.Attributes.Add("onclick","Button1.style.display='none';Button2.style.display='none';window.print();Button1.style.display='';Button2.style.display='';return false;");//打印该页,但不打印该页上的Button1和Button2 这两个按钮(window.print()之前将它们隐藏,之后再显示它们)。
}衷心感谢各位大侠的参与和回复!。