ASP DOT NET

Friday, June 22, 2018

Q.How to do header freez in gridview ?

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div style="width:478px;border:1px solid #084B8A;color:#ffffff;font-weight:bold;">
        <table bgcolor="#3090C7" rules="all" >
            <tr>
                <td style ="width:71px;">Pub ID</td>
                <td style ="width:180px;">Pub Name</td>
                <td style ="width:90px;">City</td>
                <td style ="width:60px;">State</td>
                <td style ="width:78px;">Country</td>
            </tr>
        </table>
        </div>
        <div style ="height:130px; width:500px; overflow:auto;" >
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
            ShowHeader = "false" Width ="480px" >
                <AlternatingRowStyle BackColor="#9999ff" />
      <Columns>
    <asp:BoundField ItemStyle-Width = "120px" DataField="pub_id" HeaderText="pub_id" />
    <asp:BoundField ItemStyle-Width = "300px" DataField="pub_name" HeaderText="pub_name" />
    <asp:BoundField ItemStyle-Width = "100px" DataField="city" HeaderText="city" />
    <asp:BoundField ItemStyle-Width = "100px" DataField="state" HeaderText="state" />
    <asp:BoundField ItemStyle-Width = "100px" DataField="country" HeaderText="country" />
    </Columns>
            </asp:GridView>
    </div>
    </form>
</body>
</html>

Source Code


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlDataAdapter adapter = new SqlDataAdapter();
        DataSet ds = new DataSet();
        int i = 0;
        string sql = null;
        string connetionString = "Data Source=.;Initial Catalog=pubs;User ID=sa;Password=123";
        sql = "select * from publishers";
        SqlConnection connection = new SqlConnection(connetionString);
        connection.Open();
        SqlCommand command = new SqlCommand(sql, connection);
        adapter.SelectCommand = command;
        adapter.Fill(ds);
        adapter.Dispose();
        command.Dispose();
        connection.Close();
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();
    }

}

No comments:

Post a Comment

How to to select duplicate rows from sql server?

 SELECT * FROM Recruitment WHERE Email IN (SELECT Email FROM Recruitment GROUP BY Email HAVING COUNT(*) > 1); WITH CTE AS (     SELECT   ...