GridView 使用实例

连接

                <asp:TemplateField>
                    <ItemTemplate>
<asp:HyperLink ID="HyperLink1" Text="详情" NavigateUrl='<%#"M.aspx?id="+DataBinder.Eval(Container.DataItem, "id")%>' Runat="server" Target="_blank">
                    </asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>

 

<asp:HyperLink Text="打开" NavigateUrl='<%#"newpage.aspx?name="+DataBinder.Eval(Container.DataItem, "vname")+"&age="+DataBinder.Eval(Container.DataItem, "iage") %>' Runat="server" Target="_blank">

 


 

ajax的控件工具包AJAX Control Toolkit 

http://msdn.microsoft.com/zh-cn/magazine/cc164247.aspx

ModalPopupExtender控件学习笔记  http://www.cnblogs.com/SilverLight/archive/2009/01/08/1319970.html

 

ModalPopupExtender控件和gridview的结合使用 http://hi.baidu.com/robinapecn/blog/item/ca52f6cfde3b7d0b93457e19.html


给gridview加入查找(搜索)功能

前台加上搜索:

<table border="0" cellpadding="4" cellspacing="0" style="width: 100%">

            <tr><td bgcolor="#f7f7de" colspan="2" style="height: 18px" valign="bottom"> 关键字:

<asp:TextBox ID="TextBox1"  runat="server"></asp:TextBox>

                   <asp:Button ID="Button1" runat="server"  OnClick="Button1_Click"  Text="查找" /></td>

            </tr>

        </table>

后台代码:  

  protected void Button1_Click(object sender, EventArgs e)

    {

        string res = "SELECT * FROM [city] WHERE ( [cityName] like '%" + TextBox1.Text.ToString() + "%') Order by [cityID] Desc";

        SqlDataSource1.SelectCommand = res;

        GridView1.DataSourceID = "SqlDataSource1";

        GridView1.DataBind();


Gridview 导出 Excel

private void Export(string FileType, string FileName)
    {
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            if (GridView1.Rows[i].Cells[0].Text.Length >= 15)
                GridView1.Rows[i].Cells[0].Text = "[" + GridView1.Rows[i].Cells[0].Text.Trim() + "]";
            GridView1.Rows[i].Cells[1].Text = "[" + GridView1.Rows[i].Cells[1].Text.Trim() + "]";//格式转为字符
            GridView1.Rows[i].Cells[2].Text = "[" + GridView1.Rows[i].Cells[2].Text.Trim() + "]";
            //GridView1.Rows[i].Cells[2].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
        }

       
        //以下三行可选,如果没有的话导出的只是当前页数据,没有其他页数据
        GridView1.AllowPaging = false;
        GridView1.AllowSorting = false;       
        ///gridviewdatabind(); //这里是绑定gridview的方法
        Response.Charset = "GB2312";
        Response.ContentEncoding = System.Text.Encoding.UTF7;
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
        Response.ContentType = FileType;
        this.EnableViewState = false;
        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        GridView1.RenderControl(hw);
        Response.Write(tw.ToString());
        Response.End();
    }

    protected void BtnExc_Click(object sender, EventArgs e)
    {
        Export("application/ms-excel", "学历认证统计表.xls");

    }

    public override void VerifyRenderingInServerForm(Control control)
    {

    }


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值