Custom Web Control
-
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
-
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
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
-
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
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