<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Technology Bits and Bytes &#187; MANOJ MATHE</title>
	<atom:link href="http://blogs.circlesource.com/author/manojmathe/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.circlesource.com</link>
	<description>CircleSource Technical Talent ShowCase</description>
	<lastBuildDate>Thu, 10 Dec 2009 20:01:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Building Connection string (ADO.NET)</title>
		<link>http://blogs.circlesource.com/2009/02/22/building-connection-string/</link>
		<comments>http://blogs.circlesource.com/2009/02/22/building-connection-string/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 07:18:21 +0000</pubDate>
		<dc:creator>MANOJ MATHE</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Building Connection string for ADO.NET]]></category>
		<category><![CDATA[Building Connection string for any database]]></category>
		<category><![CDATA[Building Connection string for database interaction]]></category>
		<category><![CDATA[Building Connection string in easy way]]></category>

		<guid isPermaLink="false">http://blogs.circlesource.com/?p=328</guid>
		<description><![CDATA[Building Connection string
Introduction:
        As we know we use to build the connection strings by copying the existing connection string and renaming the DatsourceName,UserName,Password like that but here we will be discussing about how to build the connection string without copy paste.
Approach:
There is a way to build the connection [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Building Connection string</strong></p>
<p><strong>Introduction:</strong></p>
<p>        As we know we use to build the connection strings by copying the existing connection string and renaming the DatsourceName,UserName,Password like that but here we will be discussing about how to build the connection string without copy paste.</p>
<p><strong>Approach:</strong></p>
<p>There is a way to build the connection string for any database which DotNet supports.<br />
<strong><br />
1.Open a notepad </strong></p>
<p><a rel="attachment wp-att-327" href="http://blogs.circlesource.com/2009/02/22/building-connection-string/bs1/"><img class="aligncenter size-full wp-image-327" src="http://blogs.circlesource.com/wp-content/uploads/2009/02/bs1.bmp" alt="save Notepad as" /></a></p>
<p>And save it as somename.udl where udl (Universal Data Link) is the extension the udl files are used to build the connection string we can directly use the udl file to open the connection to the database</p>
<p><strong><br />
2. Then you can find the file with the following icon as shown below </strong></p>
<p><a rel="attachment wp-att-329" href="http://blogs.circlesource.com/2009/02/22/building-connection-string/bs2/"><img class="aligncenter size-full wp-image-329" src="http://blogs.circlesource.com/wp-content/uploads/2009/02/bs2.bmp" alt="Icon" /></a></p>
<p><strong><br />
3. Now open this file by double click it will be as shown below </strong></p>
<p><a rel="attachment wp-att-330" href="http://blogs.circlesource.com/2009/02/22/building-connection-string/bs3/"><img class="aligncenter size-full wp-image-330" src="http://blogs.circlesource.com/wp-content/uploads/2009/02/bs3.bmp" alt="Provider" /></a></p>
<p>Now select the provider what ever you like from the list and click next in my case I am selecting the Oledb SqlProvider and clicking next</p>
<p><strong>4.Then you can see the screen as below </strong></p>
<p><a rel="attachment wp-att-331" href="http://blogs.circlesource.com/2009/02/22/building-connection-string/bs4/"><img class="aligncenter size-full wp-image-331" src="http://blogs.circlesource.com/wp-content/uploads/2009/02/bs4.bmp" alt="Details" /></a></p>
<p>then we need to provide the server name ,username if you are not using windows authentication and check the allow saving password option for saving the password in the file now select the database to which you need the connection and then click ok.</p>
<p><strong>Note: &#8211; You can find the database list if the details provided by you are valid </strong></p>
<p><strong>5. Now the connection string is ready </strong></p>
<p><strong> How to use this:</strong><br />
              1.You can directly use the udl file to open the connection and connect to the database but the limitation is it is supported<br />
                  by oledb Providers only.Sample code</p>
<p>                 <code>OleDbConnection connection = new OleDbConnection("File Name= D:\\connection.udl");<br />
                 OleDbCommand command = new OleDbCommand("select * from Cities",connection);<br />
                 OleDbDataReader reader;<br />
                 try<br />
                 {<br />
                     connection.Open();<br />
                     reader = command.ExecuteReader();<br />
                     while (reader.Read())<br />
                     {<br />
                            ListBox1.Items.Add(reader["Cities"].ToString());<br />
                            ListBox2.Items.Add(reader["Cities"].ToString());<br />
                      }<br />
                      ListBox1.DataBind();<br />
                      ListBox2.DataBind();<br />
                 }<br />
                catch (Exception error)<br />
                { }<br />
                finally<br />
                {<br />
                  connection.Close();<br />
                 }</code></p>
<p>              2. You can directly get the connection string from the file and we can use directly in our code<br />
              Open the file with notepad as shown below</p>
<p><a rel="attachment wp-att-332" href="http://blogs.circlesource.com/2009/02/22/building-connection-string/bs5/"><img class="aligncenter size-full wp-image-332" src="http://blogs.circlesource.com/wp-content/uploads/2009/02/bs5.bmp" alt="Opening the file" /></a></p>
<p>                And there you can find your connection string like this</p>
<p>               [oledb]<br />
               ; Everything after this line is an OLE DB initstring<br />
               <strong><br />
                 Provider=SQLOLEDB.1;Password=mypassword;Persist Security Info=True;User ID=username;Initial<br />
                 Catalog=datbasename;Data Source=servername</strong></p>
<p><strong>Conclusion: -</strong></p>
<p><strong>By using this udl files we can build connection string for any type of database easily.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.circlesource.com/2009/02/22/building-connection-string/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dynamically creation of web controls and binding Validations Using ASP.NET</title>
		<link>http://blogs.circlesource.com/2009/02/05/dynamically-creation-of-web-controls-and-binding-with-validations/</link>
		<comments>http://blogs.circlesource.com/2009/02/05/dynamically-creation-of-web-controls-and-binding-with-validations/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 12:20:50 +0000</pubDate>
		<dc:creator>MANOJ MATHE</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[Dynamically creation of web controls and binding Validations]]></category>
		<category><![CDATA[Dynamically creation of web controls and binding Validations Using ASP.NET]]></category>

		<guid isPermaLink="false">http://blogs.circlesource.com/?p=229</guid>
		<description><![CDATA[CreatingDynamicControls_Source
Introduction:-
As we know we can bind the controls to our page (aspx) in 2 ways
1. Statically :- Binding the controls while Designing
2. Dynamically :- Binding the controls at runtime
Everyone know how to bind statically but there may be some cases where we need to bind the control dynamically .One of those cases is when our [...]]]></description>
			<content:encoded><![CDATA[<p><a rel="attachment wp-att-236" href="http://blogs.circlesource.com/2009/02/05/dynamically-creation-of-web-controls-and-binding-with-validations/creatingdynamiccontrols2/">CreatingDynamicControls_Source</a><br />
<strong>Introduction:-</strong></p>
<p>As we know we can bind the controls to our page (aspx) in 2 ways<br />
1. Statically :- Binding the controls while Designing<br />
2. Dynamically :- Binding the controls at runtime</p>
<p>Everyone know how to bind statically but there may be some cases where we need to bind the control dynamically .One of those cases is when our controls are keep on changing like I have a registration site in which the control type may keep on changing then I may need to go for binding the controls dynamically .<br />
<strong><br />
Approach:</strong></p>
<p>For binding the controls I need the data what are the controls I want to bind and what is the id to be given and what are the properties to be provided etc.,</p>
<p>This can be provided by 2 ways </p>
<p><span id="more-229"></span></p>
<p>1. Using database (This is my approach)<br />
2. Using Xml file</p>
<p>I am creating one example (registration Page) where I am getting the data from the database as a table and based on this table I will be binding my controls to the page as we can see below</p>
<p><img class="aligncenter size-full wp-image-231" src="http://blogs.circlesource.com/wp-content/uploads/2009/02/picture1.bmp" alt="picture1" width="577" height="219" /></p>
<p>My Controls Data from database</p>
<p><strong>ControlText : </strong>- Text to be Displayed</p>
<p><strong>ControlType :</strong>-</p>
<p>1 &#8211; TextBox Control<br />
2 &#8211; DropDown Control<br />
3 &#8211; DateTime Control<br />
4 &#8211; Buttom Control</p>
<p><strong>MaxLength:</strong>- Defining the maximum length for textbox</p>
<p><strong>Manditory :</strong>- Based On this we will be binding the required field validation</p>
<p><strong>HelpText :</strong>- This is used to bind as ToolTip for the control</p>
<p><strong>Source :</strong>- Use for binding data source for dropdown controls</p>
<p><img class="aligncenter size-full wp-image-232" src="http://blogs.circlesource.com/wp-content/uploads/2009/02/picture2.bmp" alt="picture2" /></p>
<p>Page in which all the controls are generated dynamically</p>
<p><strong>Implementation:</strong></p>
<p>As we know all the server control are under System.Web.UI.WebControls namespace</p>
<p>I will be getting the tabel into a dataset for suppose the name is controlsDataSet</p>
<p><code>///<br />
/// Method usd to bind the controls<br />
///<br />
///<br />
private void BuldControls(DataSet controlsDataSet)<br />
{<br />
Table table = new Table();<br />
table.Style.Add("align", "center");</code></p>
<p>// Looping the dataset and get the values<br />
foreach (DataRow datarow in controlsDataSet.Tables[0].Rows)<br />
{<br />
int controlType =<br />
Convert.ToInt32(datarow["ControlType"].ToString());<br />
string controlText = datarow ["ControlText"].ToString();</p>
<p>TableRow newRow = new TableRow();<br />
TableCell textCell = new TableCell();</p>
<p>// Binding the text<br />
textCell.Text = controlText;<br />
newRow.Cells.Add(textCell);</p>
<p>TableCell valueCell = new TableCell();<br />
Control[] cntrlCollection=new Control[4];</p>
<p>// Checking the control Type<br />
switch(controlType)<br />
{<br />
// If TextBox<br />
case 1:<br />
cntrlCollection = this.BindTextBox(control);<br />
break;</p>
<p>// If DropDown<br />
case 2:<br />
cntrlCollection = this.BindDropDown(control);<br />
break;</p>
<p>// If DateTime<br />
case 3:<br />
cntrlCollection = this.BindDateTime(control);<br />
break;</p>
<p>// If Button<br />
case 4:<br />
cntrlCollection = this.BindButton(control);<br />
break;</p>
<p>}</p>
<p>// Adding th controls to the table cell<br />
foreach (Control cntrl in cntrlCollection)<br />
{<br />
if (cntrl != null)<br />
{<br />
valueCell.Controls.Add(cntrl);<br />
}<br />
}</p>
<p>newRow.Cells.Add(valueCell);<br />
table.Rows.Add(newRow);<br />
}</p>
<p>// Adding the table to the main panel<br />
this.pnlControls.Controls.Add(table);<br />
}</p>
<p>Creating controls dynamically is not a big matter but we have bind in such a way that when we are retriving it should not be a problem so we need to give the ids of the controls as below</p>
<p>///<br />
/// Method to bind the DropDown<br />
///<br />
///<br />
///<br />
private Control[] BindTextBox(DataRow datarow)<br />
{<br />
// Retriving the values from the datarow<br />
int controlId = Convert.ToInt32(datarow["Id"].ToString());<br />
int length = Convert.ToInt32(datarow["MaxLengh"].ToString());<br />
bool required =<br />
Convert.ToBoolean(datarow["Manditory"].ToString());<br />
string helpText = datarow["HelpText"].ToString();<br />
string controlText = datarow["ControlText"].ToString();</p>
<p>// Creating the controls array<br />
Control[] controls = new Control[4];</p>
<p>// creating the textbox<br />
TextBox textbox = new TextBox();<br />
textbox.ID = string.Concat(&#8220;txt&#8221;, controlId);<br />
textbox.ToolTip = helpText;</p>
<p>// Checking the length<br />
if (length != 0)<br />
{<br />
textbox.MaxLength = length;<br />
}</p>
<p>// Adding the textbox to the control array<br />
controls[0] = textbox;</p>
<p>// Checking id manditory<br />
if (required)<br />
{<br />
controls[1] = this.BindRequiredvalidator(controlId,<br />
textbox.ID, controlText);<br />
}<br />
return controls;<br />
}</p>
<p>Suppose I am bind for the name column the textbox id becomes like this<br />
“txt_1” and while saving also we can save accordingly.</p>
<p>So this is the way how to bind the controls and now coming to validation controls (I and using the controls provided my the VS).I am showing you a example where I am bind a validation control to textbox as shown below</p>
<p>private RequiredFieldValidator BindRequiredvalidator(int Id, string<br />
controlId, string controlText)<br />
{<br />
RequiredFieldValidator requiredFieldValidator = new<br />
RequiredFieldValidator();<br />
requiredFieldValidator.ID = string.Concat(&#8220;rfv&#8221;, Id);<br />
requiredFieldValidator.ControlToValidate = controlId;<br />
requiredFieldValidator.SetFocusOnError = true;<br />
requiredFieldValidator.ErrorMessage = string.Concat(&#8220;Enter &#8220;,<br />
controlText);<br />
return requiredFieldValidator;</p>
<p>}</p>
<p>For this method I will be passing the Id , ControlId (Like textbox control id) which need to be validated ,controlText used for error messaeges</p>
<p>And after doing all these we can see the paeg with validation controls like this</p>
<p><img class="aligncenter size-full wp-image-233" src="http://blogs.circlesource.com/wp-content/uploads/2009/02/picture3.bmp" alt="picture3" /></p>
<p>With Validation controls</p>
<p><strong>Advantages over binding controls statically:</strong></p>
<p>1. Suppose we need to add 10 controls and we are using those statically but now I need to change my control type like a textbox to be changed to dropdown then I need to change all my code once again but this easier while binding controls dynamically.<br />
2. Can bind any validation to any control dynamically.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.circlesource.com/2009/02/05/dynamically-creation-of-web-controls-and-binding-with-validations/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
