Friday, October 13, 2023

GRIDEVIEW CLASS AND OBJECT CONCEPT

 Code  inside the class   file  (  my.cs)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;


using System.Data.SqlClient;


public class my

{


    SqlConnection cn;

    SqlCommand cm;

    public SqlDataReader dr;


    public string datas;


    public string display()

    {

        string cs = @"path database location";

        cn = new SqlConnection(cs);

        cn.Open();


        string k1 = "select id,name from student";

        cm = new SqlCommand(k1, cn);

        dr = cm.ExecuteReader();

        return k1;

    }

}



CODE  INSIDE  BUTTON CLICK  EVENT IN ASPX PAGE 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;


public partial class classobjectgridview : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {


    }

    protected void Button1_Click(object sender, EventArgs e)

    {

        my m1 = new my();

        GridView1.DataSource = m1.dr;

        GridView1.DataBind();


    }

}








No comments:

Post a Comment

ADVANCE 2025

 HTML TABLE SCROLL BAR  <style>      .table-container {             width: 100%;             overflow-x: auto; /* Enables horizontal s...