Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Custom Web Control

Custom Web Control

Scheduled Pinned Locked Moved ASP.NET
helphtmldatabasedesignsysadmin
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jinnyb
    wrote on last edited by
    #1

    Hi I have a datagrid control using the web control library ,now it works fine when i do the following using System; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Xml; namespace WebControlDynamicDatagrid { /// /// Summary description for WebCustomControl1. /// [DefaultProperty("Text"), ToolboxData("<{0}:DynamicDatagrid runat=server>")] public class DynamicDatagrid : System.Web.UI.WebControls.DataGrid { private string txtProp=""; [Bindable(true), Category("Appearance"), DefaultValue("")] public string jinny { get { return txtProp; } set { txtProp = value; } } /// /// Render this control to the output parameter specified. /// /// The HTML writer to write out to protected override void Render(HtmlTextWriter output) { System.Data.SqlClient.SqlConnection mySQLConnect = new SqlConnection("Server = localhost;Initial Catalog = Northwind;UID = sa ; PWD =a"); mySQLConnect.Open(); SqlCommand myCmd = new SqlCommand("select * from orders", mySQLConnect); System.Data.SqlClient.SqlDataAdapter myAdapter = new SqlDataAdapter(myCmd); DataSet ds = new DataSet(); myAdapter.Fill(ds, "Test"); DataGrid dg = new DataGrid(); dg.DataSource = ds.Tables[0]; dg.DataBind(); dg.RenderControl(output); // Controls.Add(dg); // output.Write(dg); } } } and add the control to the tool box and use the drag and drop i get the results but now is the real problem i want the that the sqlquery query be passed by the user when he say clicks the buton on the web form . PLs help i want to send the query dynamically from the form .U might wonder y I m doing so but that is the requirement of the application. Patel Neelesh A

    J 1 Reply Last reply
    0
    • J jinnyb

      Hi I have a datagrid control using the web control library ,now it works fine when i do the following using System; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Xml; namespace WebControlDynamicDatagrid { /// /// Summary description for WebCustomControl1. /// [DefaultProperty("Text"), ToolboxData("<{0}:DynamicDatagrid runat=server>")] public class DynamicDatagrid : System.Web.UI.WebControls.DataGrid { private string txtProp=""; [Bindable(true), Category("Appearance"), DefaultValue("")] public string jinny { get { return txtProp; } set { txtProp = value; } } /// /// Render this control to the output parameter specified. /// /// The HTML writer to write out to protected override void Render(HtmlTextWriter output) { System.Data.SqlClient.SqlConnection mySQLConnect = new SqlConnection("Server = localhost;Initial Catalog = Northwind;UID = sa ; PWD =a"); mySQLConnect.Open(); SqlCommand myCmd = new SqlCommand("select * from orders", mySQLConnect); System.Data.SqlClient.SqlDataAdapter myAdapter = new SqlDataAdapter(myCmd); DataSet ds = new DataSet(); myAdapter.Fill(ds, "Test"); DataGrid dg = new DataGrid(); dg.DataSource = ds.Tables[0]; dg.DataBind(); dg.RenderControl(output); // Controls.Add(dg); // output.Write(dg); } } } and add the control to the tool box and use the drag and drop i get the results but now is the real problem i want the that the sqlquery query be passed by the user when he say clicks the buton on the web form . PLs help i want to send the query dynamically from the form .U might wonder y I m doing so but that is the requirement of the application. Patel Neelesh A

      J Offline
      J Offline
      Javier Lozano
      wrote on last edited by
      #2

      jinnyb wrote: i want the that the sqlquery query be passed by the user when he say clicks the buton on the web form First of all, this is not good design. What stops the user from submitting "DROP TABLE orders"? Now to answer your question...Add a property to your control called Query. In the Click event handler, set the value of this property to the value of the query. Pretty straight forward. ~Javier Lozano

      J 1 Reply Last reply
      0
      • J Javier Lozano

        jinnyb wrote: i want the that the sqlquery query be passed by the user when he say clicks the buton on the web form First of all, this is not good design. What stops the user from submitting "DROP TABLE orders"? Now to answer your question...Add a property to your control called Query. In the Click event handler, set the value of this property to the value of the query. Pretty straight forward. ~Javier Lozano

        J Offline
        J Offline
        jinnyb
        wrote on last edited by
        #3

        Hey thats the problem mate i m not able to set the value .I mean when i set the value of the query in the click event by creating the object of the data grid i m not able to use the value in the Render sub of the control Thanks Kindly give some code for that so that i can make use of it THanks Regards JINNY Patel Neelesh A

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups