// Design part
<body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <br /> <asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound"> </asp:GridView> <br /> <br /> </form> </body>
//.aspx.cs page
public partial class _Default : System.Web.UI.Page { clsGrd gd = new clsGrd(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { grd_bind(); } } public void grd_bind() { DataSet ds = new DataSet(); ds = gd.selectAll(); GridView1.DataSource = ds; GridView1.DataBind(); } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes.Add("onmouseover", "this.style.cursor='hand';this.style.backgroundColor='orangered'"); e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'"); e.Row.Attributes.Add("onclick", "window.open('Default2.aspx?id=" + DataBinder.Eval(e.Row.DataItem, "id") + "','myprofilewindow','width=400,height=200,toolbar=0,resizable=0');");
} } }
//class file
public class clsGrd { protected static string str = ConfigurationManager.ConnectionStrings["conn"].ConnectionString; SqlConnection con = new SqlConnection(str);
public clsGrd() { // // TODO: Add constructor logic here // }
public DataSet selectAll() { if (con.State == ConnectionState.Open) { con.Close(); } con.Open(); SqlCommand cmd = new SqlCommand("selectall", con); cmd.CommandType = CommandType.StoredProcedure; SqlDataAdapter adp = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adp.Fill(ds); return ds; }
}
|
No responses found. Be the first to respond and make money from revenue sharing program.
|