Sorting GridView Selected DropDownList Values in Asp.Net C#

GridView Column Hide Or Remove



Gridview Display Particular Columns Hide Or Remove Run Time Using Gridview_RowCreated Event in Asp.Net C#.

                        
                           DEMO 




HTML CODING

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" OnRowCreated="GridView1_RowCreated">
    <Columns>
        <asp:BoundField DataField="country" HeaderText="COUNTRY" />
        <asp:BoundField DataField="amount" HeaderText="AMOUNT" />
        <asp:BoundField DataField="name" HeaderText="NAME" />
    </Columns>
     <HeaderStyle BackColor="#FF3300" />
            <RowStyle BackColor="Silver" />
            <AlternatingRowStyle BackColor="#9999FF" />
</asp:GridView>
       
    </div>
    </form>
</body>
</html>



                          C# CODING

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


public partial class Default4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbcon"].ToString());
        con.Open();
        SqlCommand cmd = new SqlCommand("select country,amount,name from country", con);

        SqlDataAdapter adp = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        adp.Fill(ds);

        GridView1.DataSource = ds;
        GridView1.DataBind();

    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[1].Visible = false;

        //Amount Column Not Show
    }
}

First - Add New Web Form  - Select GridView From  ToolBox 




Next - Go -To - Edit Column - Add BoundField - Change Header & DataField





Next - Go -To - Edit Column - Add BoundField - Change Header & DataField






Next - Bind Values To GridView  On Page_Load






Next - Select GridView - Go-To - Property - RowCreated 






Next - Visible = False  The Column Cell Values





Next - Run[F5] - WithOut  Column  Hide Show All Column Otherwise Hide The Columns





    
      



0 comments:

Post a Comment