tag:blogger.com,1999:blog-273884032024-02-20T01:24:15.249-08:00Rebornit's all about sharing experiences in development with .net.oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.comBlogger31125tag:blogger.com,1999:blog-27388403.post-78532602613236260502011-07-12T05:31:00.000-07:002011-07-12T05:33:10.619-07:00<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhieAaFrx1NS3FJhFbUI3ayHTC49txp6c1qxXKuDsZCSWpwXZA-XS6W6clJ58hhy2Dota1G317_K2jgmVU1ENO4OuC1JRM6ArKFIUjlOWYfgzMZVC4bYQEOQmSvVe09FGhzVBT2/s1600/executionplan.png"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 122px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhieAaFrx1NS3FJhFbUI3ayHTC49txp6c1qxXKuDsZCSWpwXZA-XS6W6clJ58hhy2Dota1G317_K2jgmVU1ENO4OuC1JRM6ArKFIUjlOWYfgzMZVC4bYQEOQmSvVe09FGhzVBT2/s320/executionplan.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5628442839159810290" /></a>oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com5tag:blogger.com,1999:blog-27388403.post-29042341890868807922010-04-30T02:59:00.000-07:002010-04-30T03:15:35.827-07:00<p>very simple tip, most of the time forgotten, is the feature of having page breaks on the schema surface, to organize printing.<br /><br />Here's a screen cast showing just that (printing a database schema from sql server management studio</p><br /><br /><a href="http://www.screencast.com/t/OWM0MjhlZDk" target="_blank"><img class="embeddedObject" src="http://content.screencast.com/users/oudinia/folders/Jing/media/58feb8ee-cbd0-49c5-ab88-1932de261247/printingschemasimage.png" width="870" height="515" border="0" /></a>oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com0tag:blogger.com,1999:blog-27388403.post-64001798302083307152009-11-02T06:55:00.001-08:002009-11-02T15:02:50.020-08:00Issue : Javascript alert message box showing up twice within an UpdatePanel, after throwing an exception<p>see also : <a href="http://www.codegain.com/index.php?option=com_content&view=article&id=563:updatepanel-in-net-35-displaying-a-c-exception-in-a-javascript-alert-message-box&catid=175:how-to">article on codegain.com</a> about the same subject.</p> <p>Finally, after a lot of playing around to reproduce what was happening, I found the solution. at first I had the following javascript code :</p> <pre class="code"><span style="color: blue"><</span><span style="color: maroon">script </span><span style="color: red">type</span><span style="color: blue">="text/javascript" </span><span style="color: red">language</span><span style="color: blue">="javascript"><br /><br /> </span><span style="color: #006400">//registers the event by adding it to the endrequests collections of the instance<br /> //This will allow it to actually listen to the event when it happens, and execute <br /> //the code in the onEndRequest function<br /> </span><span style="color: blue">function </span>pageLoad() {<br /> Sys.WebForms.PageRequestManager.getInstance().add_endRequest(onEndRequest);<br /> }<br /><br /> <span style="color: #006400">//function which will execute after the C# code gets to its end<br /> //it will then catch the exception and display it on the alert message box<br /> //the substring is just to avoid having the full exception definition, <br /> //and display only the message<br /> </span><span style="color: blue">function </span>onEndRequest(sender, args) {<br /> <span style="color: blue">if </span>(args.get_error() != <span style="color: blue">null</span>) {<br /> <span style="color: blue">var </span>msg = args.get_error().message;<br /> alert(msg.substring(msg.indexOf(<span style="color: maroon">":"</span>, 0) + 1));<br /> args.set_errorHandled(<span style="color: blue">true</span>);<br /> <span style="color: blue">return false</span>;<br /> }<br /> <span style="color: blue">else<br /> </span>{ <span style="color: blue">return false</span>; }<br /> }<br /> <span style="color: blue"></</span><span style="color: maroon">script</span><span style="color: blue">></span></pre><br /><br /><p>then I had too buttons on the page. everytime a button with no exception is clicked, the next time, the exception shows twice, and keeps incrementing on each postback.</p><br /><br /><p>here’s the full code listing for the test asp.net page and C#, with the corrected javascript.</p><br /><br /><p> </p><br /><br /><pre class="code"><span style="background: yellow"><%</span><span style="color: blue">@ </span><span style="color: maroon">Page </span><span style="color: red">Language</span><span style="color: blue">="C#" </span><span style="color: red">AutoEventWireup</span><span style="color: blue">="true" </span><span style="color: red">CodeFile</span><span style="color: blue">="Default.aspx.cs" </span><span style="color: red">Inherits</span><span style="color: blue">="_Default" </span><span style="background: yellow">%><br /><br /></span><span style="color: blue"><!</span><span style="color: maroon">DOCTYPE </span><span style="color: red">html PUBLIC </span><span style="color: blue">"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br /><</span><span style="color: maroon">html </span><span style="color: red">xmlns</span><span style="color: blue">="http://www.w3.org/1999/xhtml"><br /><</span><span style="color: maroon">head </span><span style="color: red">runat</span><span style="color: blue">="server"><br /> <</span><span style="color: maroon">title</span><span style="color: blue">></</span><span style="color: maroon">title</span><span style="color: blue">><br /> <</span><span style="color: maroon">script </span><span style="color: red">type</span><span style="color: blue">="text/javascript" </span><span style="color: red">language</span><span style="color: blue">="javascript"><br /><br /> </span><span style="color: #006400">//registers the event by adding it to the endrequests collections of the instance<br /> //This will allow it to actually listen to the event when it happens, and execute <br /> //the code in the onEndRequest function<br /> </span><span style="color: blue">function </span>pageLoad() {<br /> Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(onEndRequest); //>>Key line of code for the correction<br /> Sys.WebForms.PageRequestManager.getInstance().add_endRequest(onEndRequest);<br /> }<br /><br /> <span style="color: #006400">//function which will execute after the C# code gets to its end<br /> //it will then catch the exception and display it on the alert message box<br /> //the substring is just to avoid having the full exception definition, <br /> //and display only the message<br /> </span><span style="color: blue">function </span>onEndRequest(sender, args) {<br /> <span style="color: blue">if </span>(args.get_error() != <span style="color: blue">null</span>) {<br /> <span style="color: blue">var </span>msg = args.get_error().message;<br /> alert(msg.substring(msg.indexOf(<span style="color: maroon">":"</span>, 0) + 1));<br /> args.set_errorHandled(<span style="color: blue">true</span>);<br /> <span style="color: blue">return false</span>;<br /> }<br /> <span style="color: blue">else<br /> </span>{ <span style="color: blue">return false</span>; }<br /> }<br /> <span style="color: blue"></</span><span style="color: maroon">script</span><span style="color: blue">><br /></</span><span style="color: maroon">head</span><span style="color: blue">><br /><</span><span style="color: maroon">body</span><span style="color: blue">><br /> <</span><span style="color: maroon">form </span><span style="color: red">id</span><span style="color: blue">="form1" </span><span style="color: red">runat</span><span style="color: blue">="server"><br /> <</span><span style="color: maroon">div</span><span style="color: blue">><br /> <</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">ScriptManager </span><span style="color: red">runat</span><span style="color: blue">="server" </span><span style="color: red">ID</span><span style="color: blue">="script1" /><br /> <</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">UpdatePanel </span><span style="color: red">runat</span><span style="color: blue">="server" </span><span style="color: red">ID</span><span style="color: blue">="pnlExceptions"><br /> <</span><span style="color: maroon">ContentTemplate</span><span style="color: blue">><br /> <</span><span style="color: maroon">h4</span><span style="color: blue">></span>Exceptions thrown from C#, and displayed in a javascript alert box (works with the update panel)<span style="color: blue"></</span><span style="color: maroon">h4</span><span style="color: blue">><br /> <</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">Button </span><span style="color: red">runat</span><span style="color: blue">="server" </span><span style="color: red">ID</span><span style="color: blue">="txtExceptionInAlert" </span><span style="color: red">Text</span><span style="color: blue">="Trigger Exception" </span><span style="color: red">OnClick</span><span style="color: blue">="txtExceptionInAlert_Click" /><br /> <</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">Button </span><span style="color: red">ID</span><span style="color: blue">="Button1" </span><span style="color: red">runat</span><span style="color: blue">="server" </span><span style="color: red">Text</span><span style="color: blue">="Asynchronous post back button" /><br /> </</span><span style="color: maroon">ContentTemplate</span><span style="color: blue">><br /> </</span><span style="color: maroon">asp</span><span style="color: blue">:</span><span style="color: maroon">UpdatePanel</span><span style="color: blue">><br /> </</span><span style="color: maroon">div</span><span style="color: blue">><br /> </</span><span style="color: maroon">form</span><span style="color: blue">><br /></</span><span style="color: maroon">body</span><span style="color: blue">><br /></</span><span style="color: maroon">html</span><span style="color: blue">><br /></span></pre><br /><br /><p><a href="http://11011.net/software/vspaste"></a></p><br /><br /><p> </p><br /><br /><pre class="code"><span style="color: blue">using </span>System;<br /><br /><span style="color: blue">public partial class </span><span style="color: #2b91af">_Default </span>: System.Web.UI.<span style="color: #2b91af">Page<br /> </span>{<br /> <span style="color: blue">protected void </span>Page_Load(<span style="color: blue">object </span>sender, <span style="color: #2b91af">EventArgs </span>e)<br /> {<br /><br /> }<br /> <span style="color: gray">/// <summary><br /> /// </span><span style="color: green">throwing the exception at the click event<br /> </span><span style="color: gray">/// </summary><br /> /// <param name="sender"></param><br /> /// <param name="e"></param><br /> </span><span style="color: blue">protected void </span>txtExceptionInAlert_Click(<span style="color: blue">object </span>sender, <span style="color: #2b91af">EventArgs </span>e)<br /> {<br /> <span style="color: blue">throw new </span><span style="color: #2b91af">Exception</span>(<span style="color: #a31515">"This is an exception thrown from C# code"</span>);<br /> }<br /> }</pre><br /><br /><p> </p><br /><br /><p> </p><br /><br /><p>To Reproduce the error, comment this line in the PageLoad : Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(onEndRequest);</p><br /><br /><p>the thing, is that in Javascript, I wonder how we can tell it it’s a postback, and not a new pageLoad.</p><br /><br /><p> </p><br /><br /><p>Hope this helps !</p> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com2tag:blogger.com,1999:blog-27388403.post-50524613841626215742008-10-05T04:18:00.001-07:002008-10-05T04:18:23.177-07:00codefluent, code generation and destiny :)<p>At the airport (Casablanca to Paris), I read on a french magazine ("Programmez"), on the cd offered with trial software (one of them was called codefluent.</p> <p>3 weeks later : <br />looking for rent in Paris, I get in touch with the owner, we sit an discuss at a coffee place, to find that the owner is a Microsoft France veteran, and has his own company (a Microsoft partner).</p> <p>we discuss, then agree on the apartment. then on another meeting, we discuss software in detail, to find out that indeed he's the owner of <a target="_blank" href="http://www.codefluent.com/en-US/Default.aspx">CodeFluent</a>. </p> <p>I will probably test this code generator, which I'm sure is promising quality when developing .net applications.</p> <p>The company's name is softfluent, the software is codefluent   </p> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com1tag:blogger.com,1999:blog-27388403.post-5995897566601115602008-06-07T09:15:00.001-07:002008-07-30T11:43:23.147-07:00Development or Business Intelligence<p>Thinking about the need for Business intelligence, and how close this field has been brought to the developer, it pushed me to dig into it a little, and now, I find myself working with SSIS and SSAS quite a bit, which gave me more flexibility in my conception, and avoid complicating life through coding windows services when SSIS would do a great job; </p> <p>Also, finally I understand the difference between analytical and transactional databases; Business intelligence principles are important for to understand for many devleopers working in small to medium sized projects, in order to avoid pitfalls such as :</p> <p>- trying to create dashboards with long running complex queries; </p> <p>- using C# and windows services, when Sql Server Integration Services could do the job.</p> <p>- understand where reporting on a transactional database should stop, and switch to an OLAP database</p> <p>This and a lot more I'm still finding out. Of course, once on a large project, everyone has a specialty, yet, for the last four years, I've been working on small to medium size project (3 roles at ones often), which lead me to work with web development, business intelligence and sql server 2005 administration all at once. </p> <p>I'll be posting tips on Business Intelligence, that hopefully would be helpful!</p> <p>here are some useful links for Business Intelligence Videos :</p> <p><a href="http://www.trainingspot.com" target="_blank">http://www.trainingspot.com</a></p> <p>I personnaly have purchased the videos from trainingspot, and they have been very helpful in understanding the concepts, really great!</p> <p><a href="http://www.learnintegrationservices.com" target="_blank">http://www.learnintegrationservices.com</a></p> <p>plannning to check out this integration services videos. not too expensive :)</p> <p>Regards !</p> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com2tag:blogger.com,1999:blog-27388403.post-288314160263772612008-05-28T00:41:00.001-07:002008-05-28T18:00:44.461-07:00A positive look at unit testing<p>Often we find ourselves under stress trying to deliver a module on time. Some of the first reflexes that come to mind, are to eliminate going through some layers, or simplifying (especially the asp.net layer), and many other reflexes (including myself). </p> <p>Testing Data Access, Services and Security Layers can be easy, since it really does not require a special context to run on. As for asp.net UI and presentation layer, it's been quite difficult, until the ASP.NET MVC framework preview comes in, with the support for testing the UI layer.</p> <p><strong>Unit Test layer as a conception layer:</strong> <br />In fact, when we start unit testing, we need to know that testing is at the beginning, during and at the end of development phases. Besides, the unit tests framework is by definition a framework, now, how we use it is totally up to us. <br />To create a concept for our development of a data access layer, we can <u>use our unit testing framework</u> to </p> <p align="left"></p> <p>create methods that show us : <br />                                        1. how we will use the data access layer (opens a conception discussion) <br />                                        2. It provides us a framework for testing thoroughly our data access layer <br />                                        3. It also provides us with a controlled manner of building up the solution</p> <p align="left"></p> <p><strong>Unit Test layer as a documentation layer: <br /></strong>Finally, one of the great benefits (by experience) we went through, is the fact that the unit tests layer can serve as a documentation layer (perfect fit). <br />In one of the project we worked on, we used the Unit tests layer to train any new team members, to get up and running quickly with using the layer He/she is concerned with. It was a great way to document using code and comments, we could also create a CHM file for it, and also, since it's a collection of unit tests, it works. <br /> <br /><em>A unit tests layer, a CHM documentation file, and making sure tests work, can really be a great way to have a major part of the documentation to train new team members</em></p> <p><strong>In conclusion:</strong> <br />As much as the unit tests layer can cost in terms of resources and time, It builds up a great layer for the long term use of applications. Unit tests should be used for many layers, if not, then at least for one or two layers in the application, in order to minimize maintenance cost later on. <br />Good team work is necessary to the success of good unit tests layer. </p> <p>Useful links :</p> <p><a href="http://www.asp.net/mvc">ASP.NET MVC</a> , <a href="http://quickstarts.asp.net/3-5-extensions/mvc/default.aspx">ASP.NET MVC Quick Starts</a>, </p> <p>Comments are more than welcome</p> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com1tag:blogger.com,1999:blog-27388403.post-1416582705832036302008-03-03T02:41:00.001-08:002009-10-14T01:31:19.444-07:00C#: using Timespan to caluculate the total of hours worked based on start and end times, as well as a pause<p>recently, I came acroos the need to get the total hours in sql. by using the CLR user defined functions freature, I was able to use this function into SQL server. The nice thing, is that I unit tested the function seperately, then used it. example :</p> <p>SQL: </p> <div> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">select</span> dbo.GetTotalHours(TableName.StartTime, TableName.EndTime, TableName.Pause) <span style="color: #0000ff">as</span> TotalHoursWorked;</pre><br /><br /> <br />The function is listed below with comments. also, below is a function for splitting the hour string.<br /><br /> <br /></div><br /><br /><p>example : GetTotalHours("20:00", "06:00", 120); Important: <em>the pause is expressed in minutes (in this case, it's 120 minutes pause, or 2 hours of pause).</em><br /><br /> <br /><br /><br /> <br /></p><br /><br /><pre class="code">This function, inside an sql server project is created with the sql server attribute of [SqlFunction]. This tells sql server to execute this function<br />as an extension to sql server, which will make it run as any other sql function.</pre><br /><a href="http://11011.net/software/vspaste"></a><br /><br /><div><br /> <br /><br /><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">[Microsoft.SqlServer.Server.<span style="color: #2b91af">SqlFunction</span>]<span style="color: #0000ff"><br />public</span> <span style="color: #0000ff">string</span> GetTotalHours(<span style="color: #0000ff">string</span> StartTime, <span style="color: #0000ff">string</span> EndTime, <span style="color: #0000ff">int</span> Pause)<br /> {<br /><br /> <span style="color: #0000ff">if</span> (StartTime == EndTime)<br /> {<br /> <span style="color: #0000ff">if</span> ((StartTime == <span style="color: #0000ff">null</span>) || (EndTime == <span style="color: #0000ff">null</span>) || (StartTime == <span style="color: #006080">"00:00"</span>) || (EndTime == <span style="color: #006080">"00:00"</span>))<br /> {<br /> StartTime = <span style="color: #006080">"0:0"</span>;<br /> EndTime = <span style="color: #006080">"0:0"</span>;<br /><br /><br /> <span style="color: #0000ff">return</span> <span style="color: #006080">"00:00"</span>;<br /> }<br /> }<br /> <span style="color: #008000">//this split gives the following example StartTime 10:30 Start[0] gives 10 and start[1] gives 30</span><br /> <span style="color: #0000ff">string</span>[] Start = <span style="color: #0000ff">this</span>.SplitTimeString(StartTime);<br /> <span style="color: #0000ff">string</span>[] End = <span style="color: #0000ff">this</span>.SplitTimeString(StartTime);<br /><br /><br /> <span style="color: #008000">//timespan for the taking into consideration intervals similar to : </span><br /> <span style="color: #008000">//starttime: 20:00 and endtime 01:30</span><br /> TimeSpan tsTwentyFourHours = <span style="color: #0000ff">new</span> TimeSpan(24, 0, 0);<br /> <span style="color: #008000">//start time</span><br /> TimeSpan tsStart = <span style="color: #0000ff">new</span> TimeSpan(<span style="color: #0000ff">int</span>.Parse(Start[0]), <span style="color: #0000ff">int</span>.Parse(Start[1]), 0);<br /> <span style="color: #008000">//end time</span><br /> TimeSpan tsEnd = <span style="color: #0000ff">new</span> TimeSpan(<span style="color: #0000ff">int</span>.Parse(End[0]), <span style="color: #0000ff">int</span>.Parse(End[1]), 0);<br /><br /> TimeSpan tsPause = <span style="color: #0000ff">new</span> TimeSpan(0, Pause, 0);<br /> TimeSpan tsHoursWorked;<br /><br /> <span style="color: #0000ff">if</span> (<span style="color: #0000ff">int</span>.Parse(End[0]) < <span style="color: #0000ff">int</span>.Parse(Start[0]))<br /> {<br /> <span style="color: #008000">//Case when the it's overnight work like 20:00 to 01:30</span><br /><br /> <span style="color: #008000">//we substract start time from twenty for hours, then add the end time.</span><br /> <span style="color: #008000">//this gives us the correct measures</span><br /> tsHoursWorked = tsTwentyFourHours.Subtract(tsStart).Add(tsEnd);<br /> <span style="color: #008000">//substratct the pause</span><br /> tsHoursWorked = tsHoursWorked.Subtract(tsPause);<br /> }<br /> <span style="color: #0000ff">else</span><br /> {<br /> <span style="color: #008000">//normal hours example: 08:00 to 20:00</span><br /> <span style="color: #008000">//we simply substract the start time plus the pause from the end time</span><br /> tsHoursWorked = tsEnd.Subtract(tsStart.Add(tsPause));<br /> }<br /><br /><br /> <span style="color: #0000ff">return</span> tsHoursWorked.TotalHours.ToString() + <span style="color: #006080">":"</span> + tsHoursWorked.TotalMinutes.ToString();<br /> }</pre><br /><br /> <br /></div><br /><br /><div> This function is used in the function above.<br /> <br /></div><br /><br /><div><br /> <br /><br /><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span>[] SplitTimeString(<span style="color: #0000ff">string</span> Time)<br /> {<br /> <span style="color: #0000ff">char</span>[] ch = <span style="color: #0000ff">new</span> <span style="color: #0000ff">char</span>[] { <span style="color: #006080">':'</span>, <span style="color: #006080">'.'</span> };<br /> <span style="color: #0000ff">return</span> Time.Split(ch);<br /> }</pre><br /><br /> <br /></div><br />in the next article, will see how this function can be used upgraded to be used in sql server 2008, <em><strong>taking advantage of its Time datatype</strong></em>, using Visual Studio 2010 beta version.<br /><br /><p>Comments are welcome !</p> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com1tag:blogger.com,1999:blog-27388403.post-32136136888466281092008-02-14T02:17:00.001-08:002008-02-14T02:18:24.889-08:00Enabling Diagram support (database schema creation) in SQL Server 2005<p>Diagram support for attached or backed up databases.</p> <p>The solution has been put on this blog a while ago (nice post). I have tried searching before, yet, a few days ago, I search with one of my collegues, and found that this blog is very helpful on that. The reason for this post, is just to add another link on google, that gives somewhat a confirmed solution on this issue.</p> <p><a title="http://geekswithblogs.net/timh/archive/2006/07/05/84171.aspx" href="http://geekswithblogs.net/timh/archive/2006/07/05/84171.aspx">http://geekswithblogs.net/timh/archive/2006/07/05/84171.aspx</a></p> <p>I tried what was suggested in the above blog, did not work for me at first (it worked for others). but what did work for me is the following reply on that same post :</p> <p>Begining quote from the post above</p> <p><a href="http://geekswithblogs.net/TimH/archive/2006/07/05/84171.aspx#88124"><em><font color="#6f93e6">#</font></em></a><em><font color="#6f93e6"> </font></em><a name="88124"></a><em><font color="#6f93e6">re: Cannot add diagram to SQL Server 2005 DB: Database diagram support objects cannot be installed because this database does not have a valid owner. 8/16/2006 9:39 AM </font></em><a><em><font color="#6f93e6">Julius</font></em></a></p> <p><em><font color="#6f93e6">I tried the above mentioned solution but still was not working and displaying the same error message - if you got the same error as me then just try the follwing lines in SQL Query:</font> <br /></em></p> <div> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">EXEC</span> sp_dbcmptlevel <span style="color: #006080">'dbname'</span>, <span style="color: #006080">'90'</span>; <br /><span style="color: #0000ff">ALTER</span> <span style="color: #0000ff">AUTHORIZATION</span> <span style="color: #0000ff">ON</span> <span style="color: #0000ff">DATABASE</span>::dbname <span style="color: #0000ff">TO</span> valid_login</pre><br /></div><br /><br /><p> </p><br /><br /><p>End Quote From the blog post above</p><br /><br /><p>Comments are welcome</p> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com0tag:blogger.com,1999:blog-27388403.post-73234649010788925892008-02-07T02:11:00.001-08:002008-02-08T07:26:12.178-08:00asp.net 2.0 Roles DropDownList Control in C#<p>Translation of this post to french at : <br /><a title="http://s4n44.blogspot.com/2008/02/aspnet-20-dropdownlist-de-rles-enc.html" href="http://s4n44.blogspot.com/2008/02/aspnet-20-dropdownlist-de-rles-enc.html">http://s4n44.blogspot.com/2008/02/aspnet-20-dropdownlist-de-rles-enc.html</a></p> <p>This is a user control, which encapsulates a DropDownList, an ObjectDataSource and custom, simplified roles class. The user control will connect automatically (of course), with the aspnetdb database pointed to in the web.config <br />for vb.net users, here's a nice converter provided by Telerik (<a href="http://www.telerik.com">http://www.telerik.com</a> ) : <br /><a title="http://www.codechanger.com/" href="http://www.codechanger.com/">http://www.codechanger.com/</a></p> <p>Here's the code for the user control :</p> <div> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="background-color: #ffff00"><%@ Control Language="C#" AutoEventWireup="true" CodeFile=" ddlRoles.ascx.cs" Inherits="RoleControl" %></span><br /><span style="color: #0000ff"><</span><span style="color: #800000">asp:DropDownList</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="DropDownList1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">DataSourceID</span><span style="color: #0000ff">="sourceRoles"</span> <span style="color: #ff0000">DataTextField</span><span style="color: #0000ff">="RoleName"</span><br /> <span style="color: #ff0000">DataValueField</span><span style="color: #0000ff">="RoleName"</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="185px"</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">asp:DropDownList</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"><</span><span style="color: #800000">asp:ObjectDataSource</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="sourceRoles"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">SelectMethod</span><span style="color: #0000ff">="GetRoles"</span><br /> <span style="color: #ff0000">TypeName</span><span style="color: #0000ff">="CustomRoles"</span><span style="color: #0000ff">></</span><span style="color: #800000">asp:ObjectDataSource</span><span style="color: #0000ff">></span></pre><br /></div><br />Code behind for the user control: <br /><br /><div><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">using</span> System;<br /><br /><span style="color: #0000ff">public</span> <span style="color: #0000ff">partial</span> <span style="color: #0000ff">class</span> RoleControl : System.Web.UI.UserControl<br />{<br /> <span style="color: #0000ff">public</span> String SelectedValue<br /> {<br /> get { <span style="color: #0000ff">return</span> <span style="color: #0000ff">this</span>.DropDownList1.SelectedValue; }<br /> set { <span style="color: #0000ff">this</span>.DropDownList1.SelectedValue = <span style="color: #0000ff">value</span>; }<br /> }<br />}</pre><br /></div><br />The object datasource uses the class below :<br /><br /><div><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">using</span> System;<br /><span style="color: #0000ff">using</span> System.Web.Security;<br /><span style="color: #0000ff">using</span> System.Collections.Generic;<br /><br /><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> CustomRoles<br />{<br /> <span style="color: #0000ff">private</span> <span style="color: #0000ff">string</span> mRoleName;<br /><br /> <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> RoleName<br /> {<br /> get { <span style="color: #0000ff">return</span> mRoleName; }<br /> set { mRoleName = <span style="color: #0000ff">value</span>; }<br /> }<br /><br /> <span style="color: #008000">/// <summary></span><br /> <span style="color: #008000">/// this function, loops through all roles in the database, and builds </span><br /> <span style="color: #008000">/// a collection of CustomRoles instances into a generic list of CustomRoles</span><br /> <span style="color: #008000">/// then we return the list as the source for the dropdown. </span><br /> <span style="color: #008000">/// The RoleName property is used to bind the datavaluefield and datatextfield</span><br /> <span style="color: #008000">/// in the dropdownlist</span><br /> <span style="color: #008000">/// </summary></span><br /> <span style="color: #008000">/// <returns></returns></span><br /> <span style="color: #0000ff">public</span> List<CustomRoles> GetRoles()<br /> {<br /> <span style="color: #008000">//getroles</span><br /> <span style="color: #0000ff">string</span>[] roleslist = Roles.GetAllRoles();<br /><br /> <span style="color: #0000ff">int</span> i = 0;<br /> <span style="color: #008000">//instance of customroles</span><br /> CustomRoles br;<br /><br /> <span style="color: #008000">//create the list (or collection of CustomRoles instances)</span><br /> List<CustomRoles> lstbr = <span style="color: #0000ff">new</span> List<CustomRoles>();<br /><br /> <span style="color: #008000">//fill the list by looping through the array of strings</span><br /> <span style="color: #0000ff">foreach</span> (<span style="color: #0000ff">string</span> brole <span style="color: #0000ff">in</span> roleslist)<br /> {<br /> br = <span style="color: #0000ff">new</span> CustomRoles();<br /> br.RoleName = brole;<br /> lstbr.Add(br);<br /> }<br /> <br /> <span style="color: #0000ff">return</span> lstbr;<br /><br /> }<br /><br />}</pre><br /></div><br />Comments are welcome ! oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com2tag:blogger.com,1999:blog-27388403.post-34875153567653897762008-01-15T16:04:00.001-08:002008-01-15T16:10:36.654-08:00asp.net 2.0 and up: DropDownList in GridView (using SQLDataSource)<p>To have a dropdownlist inside a gridview, we use the property "SelectedValue='<%# Eval("datakeyfield") %>' knowing that it won't show in the intellisense. To handle null values, we can have an item with a value of null. The SQLDataSource for the dropdownlist is better off put outside the gridview, so that it does not get created as many times as the dropdownlist is.</p> <p>Here's the code for the DropDownList Template Field : <br />The Dropdownlist is Filled From a table called Categories (see schema below)</p> <div> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff"><</span><span style="color: #800000">asp:TemplateField</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="Category"</span> <span style="color: #ff0000">SortExpression</span><span style="color: #0000ff">="CategoryID"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:DropDownList</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="DropDownList1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">DataSourceID</span><span style="color: #0000ff">="SourceCategories"</span><br /> <span style="color: #ff0000">AppendDataBoundItems</span><span style="color: #0000ff">="true"</span> <span style="color: #ff0000">DataTextField</span><span style="color: #0000ff">="CategoryName"</span> <span style="color: #ff0000">DataValueField</span><span style="color: #0000ff">="CategoryID"</span><br /> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="190px"</span> <span style="color: #ff0000">Enabled</span><span style="color: #0000ff">="false"</span> <span style="color: #ff0000">SelectedValue</span><span style="color: #0000ff">='<%# Eval("CategoryID") %>'</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:ListItem</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="No Item was Selected, to handle null values"</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">=""</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:DropDownList</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">></span></pre><br /><br /> <br />In the code above, Notice the property SelectedValue, and the static Item to handle null values. to this, we add the AppendDataBoundItems Property, and the dropdownlist is ready.<br /><br /> <br />Here's the complete code listing with a functional gridview:<br /><br /> <br /><br /><br /> <br />The GridView is filled from a table Called Clients (see schema below)</div><br /><br /><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff"><</span><span style="color: #800000">div</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:GridView</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="GridView1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">AutoGenerateColumns</span><span style="color: #0000ff">="False"</span> <span style="color: #ff0000">CellPadding</span><span style="color: #0000ff">="4"</span><br /> <span style="color: #ff0000">DataSourceID</span><span style="color: #0000ff">="SourceClients"</span> <span style="color: #ff0000">ForeColor</span><span style="color: #0000ff">="#333333"</span> <span style="color: #ff0000">GridLines</span><span style="color: #0000ff">="Both"</span> <span style="color: #ff0000">Font-Names</span><span style="color: #0000ff">="Verdana"</span><br /> <span style="color: #ff0000">Font-Size</span><span style="color: #0000ff">="10px"</span> <span style="color: #ff0000">AllowSorting</span><span style="color: #0000ff">="true"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">Columns</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:BoundField</span> <span style="color: #ff0000">DataField</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #ff0000">InsertVisible</span><span style="color: #0000ff">="False"</span><br /> <span style="color: #ff0000">ReadOnly</span><span style="color: #0000ff">="True"</span> <span style="color: #ff0000">SortExpression</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:BoundField</span> <span style="color: #ff0000">DataField</span><span style="color: #0000ff">="FullName"</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="FullName"</span> <span style="color: #ff0000">SortExpression</span><span style="color: #0000ff">="FullName"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:TemplateField</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="Category"</span> <span style="color: #ff0000">SortExpression</span><span style="color: #0000ff">="CategoryID"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:DropDownList</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="DropDownList1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">DataSourceID</span><span style="color: #0000ff">="SourceCategories"</span><br /> <span style="color: #ff0000">AppendDataBoundItems</span><span style="color: #0000ff">="true"</span> <span style="color: #ff0000">DataTextField</span><span style="color: #0000ff">="CategoryName"</span> <span style="color: #ff0000">DataValueField</span><span style="color: #0000ff">="CategoryID"</span><br /> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="190px"</span> <span style="color: #ff0000">Enabled</span><span style="color: #0000ff">="false"</span> <span style="color: #ff0000">SelectedValue</span><span style="color: #0000ff">='<%# Eval("CategoryID") %>'</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:ListItem</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="No Item was Selected, to handle null values"</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">=""</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:DropDownList</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">></span><br /> <br /><br /> <span style="color: #0000ff"></</span><span style="color: #800000">Columns</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:GridView</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:SqlDataSource</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="SourceClients"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ConnectionString</span><span style="color: #0000ff">="<%$ ConnectionStrings:ClientsConnectionString %>"</span><br /> <span style="color: #ff0000">SelectCommand</span><span style="color: #0000ff">="SELECT * FROM [Clients]"</span><span style="color: #0000ff">></</span><span style="color: #800000">asp:SqlDataSource</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:SqlDataSource</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="SourceCategories"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ConnectionString</span><span style="color: #0000ff">="<%$ ConnectionStrings:ClientsConnectionString %>"</span><br /> <span style="color: #ff0000">SelectCommand</span><span style="color: #0000ff">="SELECT * FROM [Categories]"</span><span style="color: #0000ff">></</span><span style="color: #800000">asp:SqlDataSource</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">div</span><span style="color: #0000ff">></span></pre><br /></div><br />Here's are the table definitions: (int and varchar(50) are the datatypes used)<br /><br /><br /><a href="http://lh6.google.com/oooussama/R41KH8wR8hI/AAAAAAAAAHM/F9gWlbERSls/image%5B6%5D"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="206" alt="image" src="http://lh5.google.com/oooussama/R41KJswR8iI/AAAAAAAAAHU/xPtQG8WiOJI/image_thumb%5B4%5D" width="439" border="0" /></a><br /><br /><br />Screen Shot for the gridview<br /><br /><br /><a href="http://lh6.google.com/oooussama/R41Lc8wR8jI/AAAAAAAAAHc/2tY4a5jHdFo/image%5B10%5D"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="159" alt="image" src="http://lh5.google.com/oooussama/R41LeswR8kI/AAAAAAAAAHk/1hJCRCpivpc/image_thumb%5B6%5D" width="371" border="0" /></a> <br /><br /><br />Comments are welcome oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com4tag:blogger.com,1999:blog-27388403.post-20525168544083046592008-01-11T09:34:00.001-08:002008-01-11T15:25:34.892-08:00asp.net 2.0 : Handling Null values for checkbox columns wihout loosing the Bind expression (works for GridView and FormView)<p> </p> <p>I looked for this for a while (the ability to keep Bind(""), not Eval("") and Also to be able to do the check for null outside the grid, and found this technique helpful: <br />        Put the checkbox control inside a user control, and handle the null values inside it. works like a charm. <br /> <br />Here's a link to the solution where I initially found it:</p> <p><a href="http://www.telerik.com/community/forums/thread/b311D-ctttt.aspx" target="_blank">http://www.telerik.com/community/forums/thread/b311D-ctttt.aspx</a> <br />look for the last 3 posts to this forum page (Fabian Schulz)</p> <p>To go a little further, Here's the download for the source code of the CheckBox User Controls. <br /><a href="http://oooussama.brinkster.net/upload/CheckBoxUserControl.rar">CheckBoxUserControl download</a></p> <p>Here's a sample of what the code should look like :</p> <p>The EditItemTemplate is missing, but can have the same code as the ItemTemplate, since the InvalidCastException is handled by checking for null values inside the checkbox user control.  (I will update this post with an EditItemTemplate). </p> <div> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 107.34%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; height: 557px; background-color: #f4f4f4; border-bottom-style: none"><span style="background-color: #ffff00"><%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %></span><br /><br /><span style="background-color: #ffff00"><%@ Register Src="DataEntryControls/CheckBoxControl.ascx" TagName="CheckBoxControl"<br /> TagPrefix="uc1" %></span><br /><span style="color: #0000ff"><!</span><span style="color: #800000">DOCTYPE</span> <span style="color: #ff0000">html</span> <span style="color: #ff0000">PUBLIC</span> <span style="color: #0000ff">"-//W3C//DTD XHTML 1.0 Transitional//EN"</span> <span style="color: #0000ff">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"><</span><span style="color: #800000">html</span> <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">="http://www.w3.org/1999/xhtml"</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"><</span><span style="color: #800000">head</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">title</span><span style="color: #0000ff">></span>Untitled Page<span style="color: #0000ff"></</span><span style="color: #800000">title</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">head</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"><</span><span style="color: #800000">body</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">form</span> <span style="color: #ff0000">id</span><span style="color: #0000ff">="form1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">div</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:GridView</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="GridView1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">AutoGenerateColumns</span><span style="color: #0000ff">="False"</span> <span style="color: #ff0000">CellPadding</span><span style="color: #0000ff">="4"</span><br /> <span style="color: #ff0000">DataSourceID</span><span style="color: #0000ff">="SqlDataSource1"</span> <span style="color: #ff0000">GridLines</span><span style="color: #0000ff">="None"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">Columns</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:BoundField</span> <span style="color: #ff0000">DataField</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #ff0000">InsertVisible</span><span style="color: #0000ff">="False"</span><br /> <span style="color: #ff0000">ReadOnly</span><span style="color: #0000ff">="True"</span> <span style="color: #ff0000">SortExpression</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:BoundField</span> <span style="color: #ff0000">DataField</span><span style="color: #0000ff">="FullName"</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="FullName"</span> <span style="color: #ff0000">SortExpression</span><span style="color: #0000ff">="FullName"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:TemplateField</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="IsValid"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">uc1:CheckBoxControl</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="CheckBoxControl1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">Checked</span><span style="color: #0000ff">='<%# Bind("IsValid") %>'</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">Columns</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:GridView</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">div</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:SqlDataSource</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="SqlDataSource1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ConnectionString</span><span style="color: #0000ff">="<%$ ConnectionStrings:ClientsConnectionString %>"</span><br /> <span style="color: #ff0000">SelectCommand</span><span style="color: #0000ff">="SELECT * FROM [Clients]"</span><span style="color: #0000ff">></</span><span style="color: #800000">asp:SqlDataSource</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">form</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">body</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">html</span><span style="color: #0000ff">></span></pre><br />The ascx has no code behind but the page load. <br /><br /> <br />As for the table, it's very simple. ClientID int auto, FullName varchar(50) and IsValid int or bit <br /><br /> <br />Here's is the source code for the CheckBox Control : <br /><br /> <br />CheckBoxControl.ascx:</div><br /><br /><div><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="background-color: #ffff00"><%@ Control Language="C#" AutoEventWireup="true" CodeFile="CheckBoxControl.ascx.cs" Inherits="Controls_DataEntryControls_CheckBoxControl" %></span><br /><span style="color: #0000ff"><</span><span style="color: #800000">asp:CheckBox</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="CheckBox1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #0000ff">/></span></pre><br /></div><br /><br /><p>CheckBoxControl.ascx.cs</p><br /><br /><div><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">using</span> System;<br /><span style="color: #0000ff">public</span> <span style="color: #0000ff">partial</span> <span style="color: #0000ff">class</span> Controls_DataEntryControls_CheckBoxControl : System.Web.UI.UserControl<br />{<br /> <span style="color: #0000ff">private</span> <span style="color: #0000ff">bool</span> m_checked = <span style="color: #0000ff">false</span>;<br /> <span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> Page_Load(<span style="color: #0000ff">object</span> sender, EventArgs e)<br /> {<br /> m_checked = CheckBox1.Checked;<br /> }<br /> <span style="color: #0000ff">public</span> <span style="color: #0000ff">object</span> Checked<br /> {<br /> get { <span style="color: #0000ff">return</span> m_checked; }<br /> set<br /> {<br /> <span style="color: #0000ff">if</span> (<span style="color: #0000ff">value</span>.GetType() == DBNull.Value.GetType()) m_checked = <span style="color: #0000ff">false</span>;<br /> <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (<span style="color: #0000ff">value</span> == <span style="color: #0000ff">null</span>) m_checked = <span style="color: #0000ff">false</span>;<br /> <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (<span style="color: #0000ff">value</span>.GetType() == <span style="color: #0000ff">typeof</span>(<span style="color: #0000ff">bool</span>)) m_checked = (<span style="color: #0000ff">bool</span>)<span style="color: #0000ff">value</span>;<br /> <span style="color: #0000ff">else</span> m_checked = <span style="color: #0000ff">false</span>;<br /> }<br /> }<br /> <span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> Page_PreRender()<br /> { <br /> CheckBox1.Checked = m_checked; <br /> }<br />}</pre><br />Comments are welcome <br /><br /> <br />This technique is based on the fact that handling null values is the concern of the control itself, not the gridview of formview, since the control forces a specific data type for its property. I beleive we could say that this is a good application of the seperation of concern pattern in asp.net.</div> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com18tag:blogger.com,1999:blog-27388403.post-37637643028450345122008-01-05T05:52:00.001-08:002008-01-06T06:32:38.545-08:00asp.net 2.0 : TextBox User Control with TextChanged Event (Event Bubbling from user controls)<p>including a textbox in a user control can save a lot of messy code in a form, as well as encapsulate validation and other functionalities (such as ajax calendar functionality). A small challenge though, it's bubbling the textchanged event from the TextBox to the top</p> <p>Here's a link to a sample website with an aspx page and the TextBox user control in it :</p> <p>>> <a href="http://oooussama.brinkster.net/upload/TextChanged Event Sample.rar">TextBox Changed Event in a user control sample</a></p> <p>Code :</p> <p>TextBox User Control :</p> <div> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="background-color: #ffff00"><%@ Control Language="C#" AutoEventWireup="true" CodeFile="TextBox.ascx.cs" Inherits="Controls_ReferenceData_ChiffresTextBox" %></span><br /><span style="color: #0000ff"><</span><span style="color: #800000">asp:TextBox</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="TextBox1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">CssClass</span><span style="color: #0000ff">="champ"</span> <span style="color: #0000ff">/><</span><span style="color: #800000">br</span> <span style="color: #0000ff">/></span><br /><span style="color: #0000ff"><</span><span style="color: #800000">asp:RequiredFieldValidator</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="RequeiredFieldValidator1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ControlToValidate</span><span style="color: #0000ff">="TextBox1"</span><br /> <span style="color: #ff0000">ErrorMessage</span><span style="color: #0000ff">="This Field is Required"</span> <span style="color: #ff0000">Display</span><span style="color: #0000ff">="Dynamic"</span> <span style="color: #0000ff">/></span></pre><br /></div><br /><br /><p>Code Behind :</p><br /><br /><div><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">using</span> System;<br /><span style="color: #0000ff">using</span> System.Data;<br /><span style="color: #0000ff">using</span> System.Configuration;<br /><span style="color: #0000ff">using</span> System.Collections;<br /><span style="color: #0000ff">using</span> System.Web;<br /><span style="color: #0000ff">using</span> System.Web.Security;<br /><span style="color: #0000ff">using</span> System.Web.UI;<br /><span style="color: #0000ff">using</span> System.Web.UI.WebControls;<br /><span style="color: #0000ff">using</span> System.Web.UI.WebControls.WebParts;<br /><span style="color: #0000ff">using</span> System.Web.UI.HtmlControls;<br /><br /><span style="color: #0000ff">public</span> <span style="color: #0000ff">partial</span> <span style="color: #0000ff">class</span> Controls_ReferenceData_ChiffresTextBox : System.Web.UI.UserControl<br />{<br /> <span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> Page_Load(<span style="color: #0000ff">object</span> sender, EventArgs e)<br /> {<br /><br /> }<br /><br /> <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Text<br /> {<br /> get { <span style="color: #0000ff">return</span> <span style="color: #0000ff">this</span>.TextBox1.Text; }<br /> set { <span style="color: #0000ff">this</span>.TextBox1.Text = <span style="color: #0000ff">value</span>; }<br /> } <br /><br /> <span style="color: #0000ff">public</span> <span style="color: #0000ff">bool</span> AutoPostBack<br /> {<br /> get { <span style="color: #0000ff">return</span> TextBox1.AutoPostBack; }<br /> set { TextBox1.AutoPostBack = <span style="color: #0000ff">value</span>; }<br /> }<br /><br /> <span style="color: #cc6633">#region</span> <span style="color: #006080">"Other properties"</span><br /> <span style="color: #0000ff">public</span> <span style="color: #0000ff">bool</span> EnabledRfv<br /> {<br /> get { <span style="color: #0000ff">return</span> <span style="color: #0000ff">this</span>.RequeiredFieldValidator1.Enabled; }<br /> set { <span style="color: #0000ff">this</span>.RequeiredFieldValidator1.Enabled = <span style="color: #0000ff">value</span>; }<br /> }<br /><br /> <br /> <span style="color: #cc6633">#endregion</span><br /><br /> <span style="color: #0000ff">protected</span> <span style="color: #0000ff">override</span> <span style="color: #0000ff">void</span> OnInit(EventArgs e)<br /> {<br /> <span style="color: #0000ff">this</span>.TextBox1.TextChanged += <span style="color: #0000ff">new</span> EventHandler(TextBox1_TextChanged);<br /> <span style="color: #0000ff">base</span>.OnInit(e);<br /> }<br /><br /> <span style="color: #0000ff">void</span> TextBox1_TextChanged(<span style="color: #0000ff">object</span> sender, EventArgs e)<br /> {<br /> OnBubbleTextChanged(e);<br /> }<br /><br /> <span style="color: #0000ff">public</span> <span style="color: #0000ff">event</span> EventHandler BubbleTextChanged;<br /><br /> <span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> OnBubbleTextChanged(EventArgs e)<br /> {<br /> <span style="color: #0000ff">if</span> (BubbleTextChanged != <span style="color: #0000ff">null</span>)<br /> BubbleTextChanged(<span style="color: #0000ff">this</span>, e);<br /><br /> }<br /><br /><br />}</pre><br /></div><br /><br /><p> </p><br /><br /><p>For Implementation in an aspx page, here's what the code looks like:</p><br /><br /><p>Register tag</p><br /><br /><div><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="background-color: #ffff00"><%@ Register Src="Controls/DataEntryControls/TextBox.ascx" TagName="TextBox" TagPrefix="uc1" %></span></pre><br /></div><br /><br /><div> </div><br /><br /><div>Control's tag</div><br /><br /><div><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff"><</span><span style="color: #800000">uc1:TextBox</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="TextBox1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">AutoPostBack</span><span style="color: #0000ff">="true"</span> <span style="color: #ff0000">OnBubbleTextChanged</span><span style="color: #0000ff">="OnTextChanged"</span> <span style="color: #0000ff">/></span></pre><br /></div><br /><br /><p> </p><br /><br /><p>Code Behind <br /> <br /></p><br /><br /><div><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">using</span> System;<br /><span style="color: #0000ff">using</span> System.Data;<br /><span style="color: #0000ff">using</span> System.Configuration;<br /><span style="color: #0000ff">using</span> System.Collections;<br /><span style="color: #0000ff">using</span> System.Web;<br /><span style="color: #0000ff">using</span> System.Web.Security;<br /><span style="color: #0000ff">using</span> System.Web.UI;<br /><span style="color: #0000ff">using</span> System.Web.UI.WebControls;<br /><span style="color: #0000ff">using</span> System.Web.UI.WebControls.WebParts;<br /><span style="color: #0000ff">using</span> System.Web.UI.HtmlControls;<br /><br /><span style="color: #0000ff">public</span> <span style="color: #0000ff">partial</span> <span style="color: #0000ff">class</span> TextBoxWithTextChange : System.Web.UI.Page<br />{<br /> <span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> Page_Load(<span style="color: #0000ff">object</span> sender, EventArgs e)<br /> {<br /><br /> }<br /> <span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> OnTextChanged(<span style="color: #0000ff">object</span> sender, EventArgs e)<br /> {<br /> Response.Write(<span style="color: #0000ff">this</span>.TextBox1.Text);<br /> }<br /> <br />}</pre><br /></div><br /><br /><p>in the code behind, we create the method OnTextChanged to handle the event. This sample I picked out from a blog, and added the possiblity to add properties. Sadly, I search and can't find it easily, so I prefered to post something similar, for more search results regarding the textchanged event bubbling from a user conrol subject.</p><br /><br /><p>The TextChanged event does not show in the list of events for the user control. something to think about, otherwise, this technique makes it easy to develop such a functionality.</p><br /><br /><p>Comments are welcome.</p> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com10tag:blogger.com,1999:blog-27388403.post-72434682695997069512008-01-05T05:51:00.001-08:002008-01-05T05:51:59.818-08:00A User Interface Data Binding Overview in asp.net<h5>Granularity (one field, one control) :</h5> <p>A definition of databing could be having a link between the field in the datasource and a control. </p> <p>When we talk about data binding, the first thing that should come to mind, is that we are binding fields to controls. In more detail, when we use a GridView to bind it to a table, in fact we are binding each field in the database to a specific control, present in the form of a collection, which makes us say, we are binding a table to the grid, while the granular aspect of it is that we are binding many fields to many controls.</p> <h5>Binding Scripting Syntax for Grids, Datalists, Formviews and detailviews:</h5> <p>Two way binding (very popular) </p> <div> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="background-color: #ffff00"><%</span><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> # Bind(<span style="color: #006080">"fieldname"</span>) </pre><span style="background-color: #ffff00">%></span></pre><br /></div><br /><br /><p>One way Binding (ReadOnly)</p><br /><br /><div><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="background-color: #ffff00"><%</span><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> # Eval(<span style="color: #006080">"fieldname"</span>) </pre><span style="background-color: #ffff00">%></span></pre><br /></div><br />Another one is : <br /><br /><div><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="background-color: #ffff00"><%</span><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> # DataBinder.Eval(Container.DataItem, <span style="color: #006080">"fieldname"</span>) </pre><span style="background-color: #ffff00">%></span></pre><br /></div><br /><br /><p> </p><br /><br /><p>This are helper Functions. Here's how they work :</p><br /><br /><p>when we have a textbox inside a TemplateField, in a Gridview : We have the following Syntax : <br /> <br /></p><br /><br /><div><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><TemplateField><br /><EditItemTemplate><br /><asp:TextBox id=<span style="color: #006080">"txtName"</span> runat=<span style="color: #006080">"server"</span> Text=<span style="color: #006080">'<%# Bind("Name") %>'</span> /><br /></EditItemTemplate><br /></TemplateField></pre><br /><br /> <br />In fact, The Bind Method is executed during the ItemDataBound Event (one popular event in the 1.1 DataGrid control used to initilize child controls in a GridView). The Bind method helps not having to write code behind syntax to bind each field during insert and update.</div><br /><br /><div> </div><br /><br /><h5>Best Practices using the SqlDataSource Control :</h5><br /><br /><div>If we notice, using SQLDataSource, (note : thanks Adnane for the tip), there's a property named DataSourceMode :</div><br /><br /><div>This property is really great, since it gives us DataSet Mode and DataReader Mode. DataSet Mode is set by default, nice, that way The paging and sorting can work by default. </div><br /><br /><div> </div><br /><br /><div><a href="http://lh5.google.com/oooussama/R3-LeMwR8fI/AAAAAAAAAG8/7AIQfP2qHMQ/image59"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="283" alt="image" src="http://lh3.google.com/oooussama/R3-LfswR8gI/AAAAAAAAAHE/by2TUMrBQKE/image_thumb57" width="721" border="0" /></a> </div><br /><br /><div> </div><br /><br /><div>When to change the DataSourceMode property:</div><br /><br /><div>For better use, there' no need in using the default mode to fill a DropDownList or a ListBox, instead we choose DataReader Mode, which will be of course more efficient.</div><br /><br /><div> </div><br /><br /><div>For differences between DataReader and DataSet, please take a look at a previous post (DataSet vs DataReader). this post includes links to msdn explaining the difference, as well as giving a breif overview of the difference.</div><br /><br /><div> </div><br /><br /><div>Comments are welcome <br /> <br /></div> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com0tag:blogger.com,1999:blog-27388403.post-57966673357830686052007-12-26T12:57:00.001-08:002007-12-26T12:59:48.867-08:00asp.net Show Details of a gridview row using the modalpopupextender: elegant, quick and efficient (without the modal effect)<p>the modalpopupextender is within the gridview</p> <p> Here's the gridview :</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff"><</span><span style="color: #800000">asp:GridView</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="GridView1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">AutoGenerateColumns</span><span style="color: #0000ff">="False"</span> <span style="color: #ff0000">CellPadding</span><span style="color: #0000ff">="4"</span><br /> <span style="color: #ff0000">DataKeyNames</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #ff0000">DataSourceID</span><span style="color: #0000ff">="SqlSourceClientsGrid"</span> <span style="color: #ff0000">GridLines</span><span style="color: #0000ff">="None"</span><br /> <span style="color: #ff0000">Font-Names</span><span style="color: #0000ff">="Verdana"</span> <span style="color: #ff0000">Font-Size</span><span style="color: #0000ff">="10px"</span> <span style="color: #ff0000">ForeColor</span><span style="color: #0000ff">="#333333"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">Columns</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:BoundField</span> <span style="color: #ff0000">DataField</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #ff0000">InsertVisible</span><span style="color: #0000ff">="False"</span><br /> <span style="color: #ff0000">ReadOnly</span><span style="color: #0000ff">="True"</span> <span style="color: #ff0000">SortExpression</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:BoundField</span> <span style="color: #ff0000">DataField</span><span style="color: #0000ff">="FullName"</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="FullName"</span> <span style="color: #ff0000">SortExpression</span><span style="color: #0000ff">="FullName"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:BoundField</span> <span style="color: #ff0000">DataField</span><span style="color: #0000ff">="IsValid"</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="IsValid"</span> <span style="color: #ff0000">SortExpression</span><span style="color: #0000ff">="IsValid"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:LinkButton</span> <span style="color: #ff0000">CommandArgument</span><span style="color: #0000ff">='<%# Eval("FullName") %>'</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="lnkDetails"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><br /> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="Details"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ajaxToolkit:ModalPopupExtender</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="popupDetails"</span> <span style="color: #ff0000">TargetControlID</span><span style="color: #0000ff">="lnkDetails"</span><br /> <span style="color: #ff0000">PopupControlID</span><span style="color: #0000ff">="pnlDetails"</span> <span style="color: #ff0000">PopupDragHandleControlID</span><span style="color: #0000ff">="pnlHandle"</span> <span style="color: #ff0000">CancelControlID</span><span style="color: #0000ff">="CancelButton"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Panel</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="pnlDetails"</span> <span style="color: #ff0000">Style</span><span style="color: #0000ff">="display: none; background-color: #666666"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Panel</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="pnlHandle"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">Style</span><span style="color: #0000ff">="cursor: move;"</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="200px"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">table</span> <span style="color: #ff0000">width</span><span style="color: #0000ff">="100%"</span> <span style="color: #ff0000">cellpadding</span><span style="color: #0000ff">="0"</span> <span style="color: #ff0000">cellspacing</span><span style="color: #0000ff">="0"</span> <span style="color: #ff0000">style</span><span style="color: #0000ff">="border: solid 1px #666666;"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span> <span style="color: #ff0000">style</span><span style="color: #0000ff">="background-image: url(Images/GridHeaderBg.gif)"</span><span style="color: #0000ff">></span><br /> Inspections<br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span> <span style="color: #ff0000">style</span><span style="color: #0000ff">="background-image: url(Images/GridHeaderBg.gif); text-align: right;"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Button</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="CancelButton"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="Close"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">table</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:Panel</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">div</span> <span style="color: #ff0000">id</span><span style="color: #0000ff">="divDetails"</span> <span style="color: #ff0000">style</span><span style="color: #0000ff">="background-color: #FFFFFF; border: solid 1px gray"</span><span style="color: #0000ff">></span><br /> <br /> <span style="color: #0000ff"><</span><span style="color: #800000">table</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> FullName :<br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="background-color: #ffff00"><%</span><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> # Eval(<span style="color: #006080">"FullName"</span>) </pre><span style="background-color: #ffff00">%></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> Is Valid :<br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="background-color: #ffff00"><%</span><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> # Eval(<span style="color: #006080">"IsValid"</span>) </pre><span style="background-color: #ffff00">%></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">table</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">div</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:Panel</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">Columns</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">FooterStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="#507CD1"</span> <span style="color: #ff0000">Font-Bold</span><span style="color: #0000ff">="True"</span> <span style="color: #ff0000">ForeColor</span><span style="color: #0000ff">="White"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">RowStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="#EFF3FB"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">PagerStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="#2461BF"</span> <span style="color: #ff0000">ForeColor</span><span style="color: #0000ff">="White"</span> <span style="color: #ff0000">HorizontalAlign</span><span style="color: #0000ff">="Center"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">SelectedRowStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="#D1DDF1"</span> <span style="color: #ff0000">Font-Bold</span><span style="color: #0000ff">="True"</span> <span style="color: #ff0000">ForeColor</span><span style="color: #0000ff">="#333333"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">HeaderStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="#507CD1"</span> <span style="color: #ff0000">Font-Bold</span><span style="color: #0000ff">="True"</span> <span style="color: #ff0000">ForeColor</span><span style="color: #0000ff">="White"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">EditRowStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="#2461BF"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">AlternatingRowStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="White"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:GridView</span><span style="color: #0000ff">></span></pre><br /></div><br /><br /><p>The most important port of the code, is the Template Field Below is its code :</p><br /><br /><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff"><</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:LinkButton</span> <span style="color: #ff0000">CommandArgument</span><span style="color: #0000ff">='<%# Eval("FullName") %>'</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="lnkDetails"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><br /> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="Details"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ajaxToolkit:ModalPopupExtender</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="popupDetails"</span> <span style="color: #ff0000">TargetControlID</span><span style="color: #0000ff">="lnkDetails"</span><br /> <span style="color: #ff0000">PopupControlID</span><span style="color: #0000ff">="pnlDetails"</span> <span style="color: #ff0000">PopupDragHandleControlID</span><span style="color: #0000ff">="pnlHandle"</span> <span style="color: #ff0000">CancelControlID</span><span style="color: #0000ff">="CancelButton"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Panel</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="pnlDetails"</span> <span style="color: #ff0000">Style</span><span style="color: #0000ff">="display: none; background-color: #666666"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Panel</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="pnlHandle"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">Style</span><span style="color: #0000ff">="cursor: move;"</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="200px"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">table</span> <span style="color: #ff0000">width</span><span style="color: #0000ff">="100%"</span> <span style="color: #ff0000">cellpadding</span><span style="color: #0000ff">="0"</span> <span style="color: #ff0000">cellspacing</span><span style="color: #0000ff">="0"</span> <span style="color: #ff0000">style</span><span style="color: #0000ff">="border: solid 1px #666666;"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span> <span style="color: #ff0000">style</span><span style="color: #0000ff">="background-image: url(Images/GridHeaderBg.gif)"</span><span style="color: #0000ff">></span><br /> Inspections<br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span> <span style="color: #ff0000">style</span><span style="color: #0000ff">="background-image: url(Images/GridHeaderBg.gif); text-align: right;"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Button</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="CancelButton"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="Close"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">table</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:Panel</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">div</span> <span style="color: #ff0000">id</span><span style="color: #0000ff">="divDetails"</span> <span style="color: #ff0000">style</span><span style="color: #0000ff">="background-color: #FFFFFF; border: solid 1px gray"</span><span style="color: #0000ff">></span><br /> <br /> <span style="color: #0000ff"><</span><span style="color: #800000">table</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> FullName :<br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="background-color: #ffff00"><%</span><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> # Eval(<span style="color: #006080">"FullName"</span>) </pre><span style="background-color: #ffff00">%></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> Is Valid :<br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="background-color: #ffff00"><%</span><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> # Eval(<span style="color: #006080">"IsValid"</span>) </pre><span style="background-color: #ffff00">%></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">table</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">div</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:Panel</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">></span></pre><br /></div><br /><br /><p>The code in the template field contains, the modalpopupextender as well as the panels and buttons related to it. this makes it a great details window.</p><br /><br /><p>Here's the complete code listing:</p><br /><br /><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="background-color: #ffff00"><%@ Page Language="C#" AutoEventWireup="true" CodeFile="ModalPopupExtenderDemo.aspx.cs"<br /> Inherits="ModalPopupExtenderDemo" %></span><br /><br /><span style="color: #0000ff"><!</span><span style="color: #800000">DOCTYPE</span> <span style="color: #ff0000">html</span> <span style="color: #ff0000">PUBLIC</span> <span style="color: #0000ff">"-//W3C//DTD XHTML 1.0 Transitional//EN"</span> <span style="color: #0000ff">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"><</span><span style="color: #800000">html</span> <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">="http://www.w3.org/1999/xhtml"</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"><</span><span style="color: #800000">head</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">title</span><span style="color: #0000ff">></span>Modal Popup Extender Demo<span style="color: #0000ff"></</span><span style="color: #800000">title</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">head</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"><</span><span style="color: #800000">body</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">form</span> <span style="color: #ff0000">id</span><span style="color: #0000ff">="form1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">div</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:ScriptManager</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="script1"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:GridView</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="GridView1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">AutoGenerateColumns</span><span style="color: #0000ff">="False"</span> <span style="color: #ff0000">CellPadding</span><span style="color: #0000ff">="4"</span><br /> <span style="color: #ff0000">DataKeyNames</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #ff0000">DataSourceID</span><span style="color: #0000ff">="SqlSourceClientsGrid"</span> <span style="color: #ff0000">GridLines</span><span style="color: #0000ff">="None"</span><br /> <span style="color: #ff0000">Font-Names</span><span style="color: #0000ff">="Verdana"</span> <span style="color: #ff0000">Font-Size</span><span style="color: #0000ff">="10px"</span> <span style="color: #ff0000">ForeColor</span><span style="color: #0000ff">="#333333"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">Columns</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:BoundField</span> <span style="color: #ff0000">DataField</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #ff0000">InsertVisible</span><span style="color: #0000ff">="False"</span><br /> <span style="color: #ff0000">ReadOnly</span><span style="color: #0000ff">="True"</span> <span style="color: #ff0000">SortExpression</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:BoundField</span> <span style="color: #ff0000">DataField</span><span style="color: #0000ff">="FullName"</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="FullName"</span> <span style="color: #ff0000">SortExpression</span><span style="color: #0000ff">="FullName"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:BoundField</span> <span style="color: #ff0000">DataField</span><span style="color: #0000ff">="IsValid"</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="IsValid"</span> <span style="color: #ff0000">SortExpression</span><span style="color: #0000ff">="IsValid"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:LinkButton</span> <span style="color: #ff0000">CommandArgument</span><span style="color: #0000ff">='<%# Eval("FullName") %>'</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="lnkDetails"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><br /> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="Details"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ajaxToolkit:ModalPopupExtender</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="popupDetails"</span> <span style="color: #ff0000">TargetControlID</span><span style="color: #0000ff">="lnkDetails"</span><br /> <span style="color: #ff0000">PopupControlID</span><span style="color: #0000ff">="pnlDetails"</span> <span style="color: #ff0000">PopupDragHandleControlID</span><span style="color: #0000ff">="pnlHandle"</span> <span style="color: #ff0000">CancelControlID</span><span style="color: #0000ff">="CancelButton"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Panel</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="pnlDetails"</span> <span style="color: #ff0000">Style</span><span style="color: #0000ff">="display: none; background-color: #666666"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Panel</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="pnlHandle"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">Style</span><span style="color: #0000ff">="cursor: move;"</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="200px"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">table</span> <span style="color: #ff0000">width</span><span style="color: #0000ff">="100%"</span> <span style="color: #ff0000">cellpadding</span><span style="color: #0000ff">="0"</span> <span style="color: #ff0000">cellspacing</span><span style="color: #0000ff">="0"</span> <span style="color: #ff0000">style</span><span style="color: #0000ff">="border: solid 1px #666666;"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span> <span style="color: #ff0000">style</span><span style="color: #0000ff">="background-image: url(Images/GridHeaderBg.gif)"</span><span style="color: #0000ff">></span><br /> Inspections<br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span> <span style="color: #ff0000">style</span><span style="color: #0000ff">="background-image: url(Images/GridHeaderBg.gif); text-align: right;"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Button</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="CancelButton"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="Close"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">table</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:Panel</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">div</span> <span style="color: #ff0000">id</span><span style="color: #0000ff">="divDetails"</span> <span style="color: #ff0000">style</span><span style="color: #0000ff">="background-color: #FFFFFF; border: solid 1px gray"</span><span style="color: #0000ff">></span><br /> <br /> <span style="color: #0000ff"><</span><span style="color: #800000">table</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> FullName :<br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="background-color: #ffff00"><%</span><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> # Eval(<span style="color: #006080">"FullName"</span>) </pre><span style="background-color: #ffff00">%></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> Is Valid :<br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="background-color: #ffff00"><%</span><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> # Eval(<span style="color: #006080">"IsValid"</span>) </pre><span style="background-color: #ffff00">%></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">table</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">div</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:Panel</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">Columns</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">FooterStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="#507CD1"</span> <span style="color: #ff0000">Font-Bold</span><span style="color: #0000ff">="True"</span> <span style="color: #ff0000">ForeColor</span><span style="color: #0000ff">="White"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">RowStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="#EFF3FB"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">PagerStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="#2461BF"</span> <span style="color: #ff0000">ForeColor</span><span style="color: #0000ff">="White"</span> <span style="color: #ff0000">HorizontalAlign</span><span style="color: #0000ff">="Center"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">SelectedRowStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="#D1DDF1"</span> <span style="color: #ff0000">Font-Bold</span><span style="color: #0000ff">="True"</span> <span style="color: #ff0000">ForeColor</span><span style="color: #0000ff">="#333333"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">HeaderStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="#507CD1"</span> <span style="color: #ff0000">Font-Bold</span><span style="color: #0000ff">="True"</span> <span style="color: #ff0000">ForeColor</span><span style="color: #0000ff">="White"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">EditRowStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="#2461BF"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">AlternatingRowStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="White"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:GridView</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:SqlDataSource</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="SqlSourceClientsGrid"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ConnectionString</span><span style="color: #0000ff">="<%$ ConnectionStrings:ClientsConnectionString %>"</span><br /> <span style="color: #ff0000">DeleteCommand</span><span style="color: #0000ff">="spDeleteClients"</span> <span style="color: #ff0000">DeleteCommandType</span><span style="color: #0000ff">="StoredProcedure"</span> <span style="color: #ff0000">SelectCommand</span><span style="color: #0000ff">="spGetClients"</span><br /> <span style="color: #ff0000">SelectCommandType</span><span style="color: #0000ff">="StoredProcedure"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">DeleteParameters</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Parameter</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="Int32"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">DeleteParameters</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:SqlDataSource</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">div</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">form</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">body</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">html</span><span style="color: #0000ff">></span></pre><br /></div><br /><br /><p>I'll put the code up for the download soon. </p><br /><br /><p>here's the database table used for samples:</p><br /><br /><p><a href="http://lh6.google.com/oooussama/R3LAJnrBsLI/AAAAAAAAAGc/YZVYYn3oWqE/image%5B2%5D"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="132" alt="image" src="http://lh5.google.com/oooussama/R3LAMXrBsMI/AAAAAAAAAGk/mmDnTsaU0Hw/image_thumb" width="244" border="0" /></a> </p><br /><br /><p>the ModalPopupExtender makes it a great and easy way to show the details of a row. Here's a screen shot for what it looks like :</p><br /><br /><p><a href="http://lh3.google.com/oooussama/R3LAO3rBsNI/AAAAAAAAAGs/6bfxOw1VzhU/image%5B14%5D"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="320" alt="image" src="http://lh6.google.com/oooussama/R3LARnrBsOI/AAAAAAAAAG0/iGUEnuPs9Vo/image_thumb%5B8%5D" width="619" border="0" /></a><br /><br /> <br />Comments are welcome </p> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com0tag:blogger.com,1999:blog-27388403.post-20070538137669059692007-12-17T04:57:00.001-08:002014-01-28T05:01:40.827-08:00Visual Studio 2005 anecdote (How can we classify this behavior!!!)<div dir="ltr" style="text-align: left;" trbidi="on">
at least it's easy to reinstall, I haven't tried yet. I got around this by using visual studio 2008 beta 2 to finish my work. the express version are there also for a temporary alternative. so, plenty of options. it was harder with webmatrix and visual studio 2003.<br />
<a href="http://lh6.google.com/oooussama/R2Zx_nrBsFI/AAAAAAAAAFs/bn4WVZgkRXo/bct-162%5B3%5D"><img alt="bct-162" border="0" src="http://lh5.google.com/oooussama/R2ZyBXrBsGI/AAAAAAAAAF0/3qM2LigAxSg/bct-162_thumb%5B1%5D" height="431" style="border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px;" width="705" /></a> <br /><a href="http://lh3.google.com/oooussama/R2ZyC3rBsHI/AAAAAAAAAF8/cWyg2iC46lY/bct-161%5B3%5D"><img alt="bct-161" border="0" src="http://lh3.google.com/oooussama/R2ZyE3rBsII/AAAAAAAAAGE/-tj1uNMhdKw/bct-161_thumb%5B1%5D" height="437" style="border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px;" width="711" /></a> <br /> <br /> <br /> <a href="http://lh5.google.com/oooussama/R2ZyGXrBsJI/AAAAAAAAAGM/bbYJZOLYRSs/bct-170%5B4%5D"><img alt="bct-170" border="0" src="http://lh3.google.com/oooussama/R2ZyH3rBsKI/AAAAAAAAAGU/tUY0RidZ03M/bct-170_thumb%5B2%5D" height="439" style="border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px;" width="709" /></a></div>
oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com0tag:blogger.com,1999:blog-27388403.post-46518505283756398572007-12-12T02:35:00.001-08:002008-08-26T02:24:01.913-07:00asp.net : an alternative to multi-column DropDownList Gridview within dropdownlist / combobox (using the Ajax DropDownExtender)<p><a href="http://oooussama.brinkster.net/upload/ListBoxWithinDropDownList.rar" target="_blank"><a href="http://oooussama.brinkster.net/upload/ListBoxWithinDropDownList.rar">ListBox Within a dropdownlist Sample Code in C#.rar</a></a></p> <p><a href="http://oooussama.brinkster.net/upload/GridWithinDrodDownListAjax.rar">Grid within a dropdownlist Sample Code in C# or vb.net.rar</a></a></p> <p><a href="http://oooussama.brinkster.net/upload/GridWithinDrodDownListAjax.zip">Grid within a dropdownlist Sample Code in C# or vb.net.zip</a> </p> <p>Often, we need to put more info into the dropdownlist (multi-column). using the popupcontrol extender, a panel, and a gridview, we can have the effect of a gridview within a dropdownlist.</p> <p>Here's a screen shot :</p> <p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="122" alt="image" src="http://lh4.google.com/oooussama/R1-5Ucm3jqI/AAAAAAAAAFU/JntLxG6EJOM/image_thumb" width="229" border="0" /><a href="http://lh6.google.com/oooussama/R1-5U8m3jrI/AAAAAAAAAFc/aIYc5ee-xtQ/image5"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="91" alt="image" src="http://lh5.google.com/oooussama/R1-5Vsm3jsI/AAAAAAAAAFk/eHb-Ht7FiK4/image_thumb1" width="240" border="0" /></a></p> <p>Before the dropdownextender, two solutions were available :</p> <p>1. concatenation in the sql query or procedure (ex: Select FirstName + ' ' + LastName as FullName From Person) see this post for details on implementing a multi-column dropdownlist using techniques from SQL and the asp.net dropdownlist <br /><a title="http://forums.asp.net/p/1036228/1432282.aspx" href="http://forums.asp.net/p/1036228/1432282.aspx">http://forums.asp.net/p/1036228/1432282.aspx</a> </p> <p>2. develop or purchase a custom dropdownlist, which is still a good option (Also some information about purchase is available on the post above. Of course, there are many third party component providers to choose from). (in our company we use Telerik components others use easy ListBox).</p> <p>In one of the applications we developped lately, this method using the Ajax DropDownExtender along with the gridview (SelectedIndexChanged Event or the selection feature) was a great option, since the difficulty level is not that high.</p> <p>Here's the code for the aspx file:</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff"><</span><span style="color: #800000">asp:ScriptManager</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="script1"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Label</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="Label1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="To select a Client, Please Click here"</span><span style="color: #0000ff">></</span><span style="color: #800000">asp:Label</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ajaxToolkit:DropDownExtender</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="popupdropdown"</span> <span style="color: #ff0000">DropDownControlID</span><span style="color: #0000ff">="pnlGrid"</span><br /> <span style="color: #ff0000">TargetControlID</span><span style="color: #0000ff">="Label1"</span> <span style="color: #0000ff">/></span></pre><br /><br /> <br /></div><br /><br /><br /><br /><br /><br /><br /><br /><p>above, we can see how the dropdownextender refers to the label, as well as the panel which hosts the grid.</p><br /><br /><br /><br /><br /><br /><br /><br /><p>here's the code for the panel:</p><br /><br /><br /><br /><br /><br /><br /><br /><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><br /> <br /><br /><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff"><</span><span style="color: #800000">asp:Panel</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="pnlGrid"</span> <span style="color: #ff0000">Style</span><span style="color: #0000ff">="display: none; visibility: hidden"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:GridView</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="GridView1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">AutoGenerateColumns</span><span style="color: #0000ff">="False"</span> <span style="color: #ff0000">CellPadding</span><span style="color: #0000ff">="4"</span><br /> <span style="color: #ff0000">DataKeyNames</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #ff0000">DataSourceID</span><span style="color: #0000ff">="SqlSourceClientsGrid"</span> <span style="color: #ff0000">GridLines</span><span style="color: #0000ff">="None"</span><br /> <span style="color: #ff0000">OnRowCommand</span><span style="color: #0000ff">="GridView1_RowCommand"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">Columns</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:BoundField</span> <span style="color: #ff0000">DataField</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #ff0000">InsertVisible</span><span style="color: #0000ff">="False"</span><br /> <span style="color: #ff0000">ReadOnly</span><span style="color: #0000ff">="True"</span> <span style="color: #ff0000">SortExpression</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:BoundField</span> <span style="color: #ff0000">DataField</span><span style="color: #0000ff">="FullName"</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="FullName"</span> <span style="color: #ff0000">SortExpression</span><span style="color: #0000ff">="FullName"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:BoundField</span> <span style="color: #ff0000">DataField</span><span style="color: #0000ff">="IsValid"</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="IsValid"</span> <span style="color: #ff0000">SortExpression</span><span style="color: #0000ff">="IsValid"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:LinkButton</span> <span style="color: #ff0000">CommandName</span><span style="color: #0000ff">="Select"</span> <span style="color: #ff0000">CommandArgument</span><span style="color: #0000ff">='<%# Eval("FullName") %>'</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="LinkButton1"</span><br /> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><span style="color: #0000ff">></span>Select<span style="color: #0000ff"></</span><span style="color: #800000">asp:LinkButton</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">Columns</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:GridView</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:Panel</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:SqlDataSource</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="SqlSourceClientsGrid"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ConnectionString</span><span style="color: #0000ff">="<%$ ConnectionStrings:ClientsConnectionString %>"</span><br /> <span style="color: #ff0000">DeleteCommand</span><span style="color: #0000ff">="spDeleteClients"</span> <span style="color: #ff0000">DeleteCommandType</span><span style="color: #0000ff">="StoredProcedure"</span> <span style="color: #ff0000">SelectCommand</span><span style="color: #0000ff">="spGetClients"</span><br /> <span style="color: #ff0000">SelectCommandType</span><span style="color: #0000ff">="StoredProcedure"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">DeleteParameters</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Parameter</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="Int32"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">DeleteParameters</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:SqlDataSource</span><span style="color: #0000ff">></span></pre><br /><br /> <br /></div><br /><br /><br /><br /><br /><br /><br /><br /><p>notice the panel's visibility set to false intially, then the dropdown extender takes care of hiding and showing the "pnlGrid" control. I personnaly found this technique very useful in many cases. </p><br /><br /><br /><br /><br /><br /><br /><br /><p>  </p><br /><br /><br /><br /><br /><br /><br /><br /><p>This helps go one step beyond the regular dropdownlist for data entry forms and displaying choice lists to the user, in a flexible manner</p><br /><br /><br /><br /><br /><br /><br /><br /><p><a href="http://oooussama.brinkster.net/upload/GridWithinDrodDownListAjax.zip"></a><br /><br /> <br /><br /><br /> <br /><br /><br /> <br /></p><br /><br /><br /><br /><br /><br /><br /><br /><p>Comments are always welcome</p> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com11tag:blogger.com,1999:blog-27388403.post-46753548382592614392007-12-11T03:29:00.001-08:002007-12-11T03:34:47.214-08:00asp.net 2.0 and up, C#: User Control within formview (using properties (accessors) and stored procedures)<p>Many times, we find ourselves developing a formview, with quite a long template (item, edititem and insertitem templates). The Idea here is to include the insert and edit item templates into one user control, and then the item template into another user control. this way, we dramatically reduce the amount of code in the form, and also, get a better grip on the business logic asked for in the form.</p> <p>We will start with a very simple example. To make things simple, we'll have a Clients table, with three fields. we'll use the SQLDataSource, For binding with the formview, and stored procedures. </p> <p>Here's the database table :</p> <p><a href="http://lh5.google.com/oooussama/R150h8m3jnI/AAAAAAAAAE8/fg4WS4GMTU0/image%5B2%5D"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="89" alt="image" src="http://lh4.google.com/oooussama/R150ism3joI/AAAAAAAAAFE/ErfI48toGyU/image_thumb" width="244" border="0" /></a> Note: ClientID is an identity field (with auto-increment, seed 1)</p> <p>Here is the data entry user control :</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="background-color: #ffff00"><%@ Control Language="C#" AutoEventWireup="true" CodeFile="ClientsDataEntry.ascx.cs"<br /> Inherits="Controls_ClientsDataEntry" %></span><br /><span style="color: #0000ff"><</span><span style="color: #800000">table</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> Full Name<br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:TextBox</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="txtFullName"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> Is Valid<br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:CheckBox</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="chkIsValid"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">table</span><span style="color: #0000ff">></span></pre><br /></div><br /><br /><p>Code Behind (notice the use of properties to access the data entry controls) :</p><br /><br /><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">using</span> System;<br /><span style="color: #0000ff">using</span> System.Data;<br /><span style="color: #0000ff">using</span> System.Web;<br /><span style="color: #0000ff">using</span> System.Web.UI;<br /><span style="color: #0000ff">using</span> System.Web.UI.WebControls;<br /><span style="color: #0000ff">using</span> System.Web.UI.HtmlControls;<br /><br /><span style="color: #0000ff">public</span> <span style="color: #0000ff">partial</span> <span style="color: #0000ff">class</span> Controls_ClientsDataEntry : System.Web.UI.UserControl<br />{<br /> <span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> Page_Load(<span style="color: #0000ff">object</span> sender, EventArgs e)<br /> {<br /><br /> }<br /> <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> FullName<br /> {<br /> get { <span style="color: #0000ff">return</span> <span style="color: #0000ff">this</span>.txtFullName.Text; }<br /> set { <span style="color: #0000ff">this</span>.txtFullName.Text = <span style="color: #0000ff">value</span>; }<br /> }<br /> <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> IsValid<br /> {<br /> get<br /> {<br /> <span style="color: #0000ff">if</span> (<span style="color: #0000ff">this</span>.chkIsValid.Checked)<br /> <span style="color: #0000ff">return</span> 1;<br /> <span style="color: #0000ff">else</span><br /> <span style="color: #0000ff">return</span> 0;<br /> }<br /> set<br /> {<br /> <span style="color: #0000ff">if</span> (<span style="color: #0000ff">value</span> == 1)<br /> <span style="color: #0000ff">this</span>.chkIsValid.Checked = <span style="color: #0000ff">true</span>;<br /> <span style="color: #0000ff">else</span><br /> <span style="color: #0000ff">this</span>.chkIsValid.Checked = <span style="color: #0000ff">false</span>;<br /> }<br /> }<br />}</pre><br /></div><br /><br /><p>Here's the formview :</p><br /><br /><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff"><</span><span style="color: #800000">asp:FormView</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="FormView1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">DataSourceID</span><span style="color: #0000ff">="SqlSourceClients"</span> <span style="color: #ff0000">DefaultMode</span><span style="color: #0000ff">="Insert"</span><br /> <span style="color: #ff0000">DataKeyNames</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #ff0000">OnItemInserted</span><span style="color: #0000ff">="FormView1_ItemInserted"</span> <span style="color: #ff0000">OnItemUpdated</span><span style="color: #0000ff">="FormView1_ItemUpdated"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">EditItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">table</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">uc1:ClientsDataEntry</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="ClientsDataEntry1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">IsValid</span><span style="color: #0000ff">='<%# Bind("IsValid") %>'</span><br /> <span style="color: #ff0000">FullName</span><span style="color: #0000ff">='<%# Bind("FullName") %>'</span><span style="color: #0000ff">></</span><span style="color: #800000">uc1:ClientsDataEntry</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span> <span style="color: #ff0000">colspan</span><span style="color: #0000ff">="2"</span> <span style="color: #ff0000">align</span><span style="color: #0000ff">="right"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:LinkButton</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="UpdateButton"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">CausesValidation</span><span style="color: #0000ff">="True"</span> <span style="color: #ff0000">CommandName</span><span style="color: #0000ff">="Update"</span><br /> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="Update"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:LinkButton</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="UpdateCancelButton"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">CausesValidation</span><span style="color: #0000ff">="False"</span> <span style="color: #ff0000">CommandName</span><span style="color: #0000ff">="Cancel"</span><br /> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="Cancel"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">table</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:HiddenField</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="ClientIDLabel1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">='<%# Bind("ClientID") %>'</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">EditItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">InsertItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">table</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">uc1:ClientsDataEntry</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="ClientsDataEntry2"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">IsValid</span><span style="color: #0000ff">='<%# Bind("IsValid") %>'</span><br /> <span style="color: #ff0000">FullName</span><span style="color: #0000ff">='<%# Bind("FullName") %>'</span><span style="color: #0000ff">></</span><span style="color: #800000">uc1:ClientsDataEntry</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">td</span> <span style="color: #ff0000">colspan</span><span style="color: #0000ff">="2"</span> <span style="color: #ff0000">align</span><span style="color: #0000ff">="right"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:LinkButton</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="InsertButton"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">CausesValidation</span><span style="color: #0000ff">="True"</span> <span style="color: #ff0000">CommandName</span><span style="color: #0000ff">="Insert"</span><br /> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="Insert"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:LinkButton</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="InsertCancelButton"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">CausesValidation</span><span style="color: #0000ff">="False"</span> <span style="color: #ff0000">CommandName</span><span style="color: #0000ff">="Cancel"</span><br /> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="Cancel"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">td</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">tr</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">table</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">InsertItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:FormView</span><span style="color: #0000ff">></span></pre><br /></div><br />notice how the user control is implemented, in both the EditItemTemplate and the InsertItemTemplate, using properties to access the textboxes. this way we don't have validation code and customizations inside our formview. <br /><br /><br /><br /><br /><p>and the SqlDataSource :</p><br /><br /><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff"><</span><span style="color: #800000">asp:SqlDataSource</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="SqlSourceClients"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ConnectionString</span><span style="color: #0000ff">="<%$ ConnectionStrings:ClientsConnectionString %>"</span><br /> <span style="color: #ff0000">InsertCommand</span><span style="color: #0000ff">="spCreateClients"</span> <span style="color: #ff0000">InsertCommandType</span><span style="color: #0000ff">="StoredProcedure"</span> <span style="color: #ff0000">SelectCommand</span><span style="color: #0000ff">="spGetClientsByID"</span><br /> <span style="color: #ff0000">SelectCommandType</span><span style="color: #0000ff">="StoredProcedure"</span> <span style="color: #ff0000">UpdateCommand</span><span style="color: #0000ff">="spUpdateClients"</span> <span style="color: #ff0000">UpdateCommandType</span><span style="color: #0000ff">="StoredProcedure"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">SelectParameters</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:ControlParameter</span> <span style="color: #ff0000">ControlID</span><span style="color: #0000ff">="GridView1"</span> <span style="color: #ff0000">DefaultValue</span><span style="color: #0000ff">="0"</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #ff0000">PropertyName</span><span style="color: #0000ff">="SelectedValue"</span><br /> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="Int32"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">SelectParameters</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">UpdateParameters</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Parameter</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="ClientID"</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="Int32"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Parameter</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="FullName"</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="String"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Parameter</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="IsValid"</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="Int32"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">UpdateParameters</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">InsertParameters</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Parameter</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="FullName"</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="String"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:Parameter</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="IsValid"</span> <span style="color: #ff0000">Type</span><span style="color: #0000ff">="Int32"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">InsertParameters</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:SqlDataSource</span><span style="color: #0000ff">></span></pre><br /></div><br /><br /><p>Simplicity, encapsulation, and seperation of concern, make things much easier to maintain.</p><br /><br /><p>here's the full code download. the database is included in the appdata folder, a simple view in browser code to the default.aspx will run the sample. <br /> <br /><a href="http://oooussama.brinkster.net/upload/UserControlInFormViewSample.rar" target="_blank">UserControl In Fromview Sample Code in C#.rar</a> <br /><br /> <br /><a href="http://oooussama.brinkster.net/upload/UserControlInFormViewSample.zip" target="_blank">UserControl In Formview Sample Code in C#.zip</a> <br /><br /> <br />Comments are welcome.</p> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com0tag:blogger.com,1999:blog-27388403.post-56123697201049726682007-12-02T16:45:00.001-08:002007-12-03T16:43:08.587-08:00asp.net : Add confirm delete to a GridView delete buttonC# <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 38px; background-color: #f4f4f4"> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">OnClientClick=<span style="color: #006080">'<%# "return confirm(\"do you want to delete " + Eval("Name") + "\")" %>'</span>></pre><br /></div><br />Visual basic<br /><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">OnClientClick=<span style="color: #006080">'<%# "return confirm(""do you want to delete " + Eval("Name") + """)" %>'</span>></pre><br /></div><br />using the onclientclick event of the button, linkbutton, or imagebutton control, we can add the confirm javascript function. <br /><br /><br />for each double quote closing or opening a string, we need to add the escape character \. The Eval function takes as a parameter whichever field name we need to display in the confirm section. <br /><br /><br /><a href="http://lh4.google.com/oooussama/R1NRvcm3jlI/AAAAAAAAAEs/iS3U5lyktMc/image%5B2%5D"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="126" alt="image" src="http://lh4.google.com/oooussama/R1NRwcm3jmI/AAAAAAAAAE0/HBQ9kCS2Id0/image_thumb" width="244" border="0" /></a> <br /><br /><br />this technique has been around since .net 1.0, implemented in different ways. the onclientclick event is new in .net 2.0 and up, which makes it useful in this situation. <br /><br /><p>Comments are welcome</p> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com7tag:blogger.com,1999:blog-27388403.post-41544364407715470982007-12-02T12:37:00.001-08:002007-12-02T16:10:15.998-08:00asp.net (DataAccess): Filling a DropDownList using a DataReader With the SqlDataSource<p>the SqlDataSource component, has a property called datasource mode :</p> <p><a href="http://lh4.google.com/oooussama/R1MXmcm3jiI/AAAAAAAAAEU/8at750TVWOk/image%5B2%5D"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="234" alt="image" src="http://lh6.google.com/oooussama/R1MXn8m3jjI/AAAAAAAAAEc/73rzFdIk0yY/image_thumb" width="211" border="0" /></a> </p> <p>this property allows retreiving data using "DataSet" mode (the default), or "DataReader" mode.</p> <p>so, for those who trust the SqlDataSource component, there's one way to bind grids, dropdownlists, formview and other controls. It is suitable for many situations, but not all. </p> <p>Comments are welcome!</p> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com0tag:blogger.com,1999:blog-27388403.post-42031106980513028482007-11-30T08:06:00.001-08:002008-01-04T02:30:01.914-08:00useful links of free stuff on the net to get up and running with asp.net and sql server 2005.<p><a href="http://www.asp.net/community/projects/">http://www.asp.net/community/projects/</a> <br />asp.net 2.0 starter kit, with full source code, to get up to speed quickly at work, or startup a business</p> <p><a href="http://ajax.asp.net/toolkit">http://ajax.asp.net/toolkit</a>   <br />the Microsoft ajax control toolkit</p> <p><a href="http://ajax.asp.net">http://ajax.asp.net</a>  <br />all about Microsoft implementation AJAX </p> <p><a title="http://ajaxload.info/" href="http://ajaxload.info/">http://ajaxload.info/</a> <br />generate and download loading... GIF animations without hastle, and without imageready.</p> <p><a href="http://www.w3schools.com">http://www.w3schools.com</a> <br />great for beginners for html, xml, css, javascript, asp.net etc... works for intermediate level also (great site)</p> <p><a href="http://www.databaseanswers.com">http://www.databaseanswers.com</a> <br />great starter kit database designs for almost any business need (over 200 data models)</p> <p><a href="http://msdn2.microsoft.com/express/bb403186.aspx">http://msdn2.microsoft.com/express/bb403186.aspx</a>   <br />starter database schemas for sql server 2005</p> <p><a title="http://www.asp.net/learn/" href="http://www.asp.net/learn/">http://www.asp.net/learn/</a>  <br />many free .net videos for asp.net, sql server 2005, and visual studio needs</p> <p>Enjoy!</p> <p>Comments are welcome.</p> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com1tag:blogger.com,1999:blog-27388403.post-79813762655301856552007-11-30T07:44:00.001-08:002008-02-07T02:39:57.056-08:00asp.net 2.0 Security: a role management module in C#<p>instead of everytime developing the code to manage roles in the aspnetdb database, it is just as easy to put all the logic and code inside a user control. the control has one property, which is the UserName, once we have the username, we can add that user to a role, or to many roles, as well as removing the user from different roles.</p> <p>in a few screenshots and code, I hope this article will help getting up to speed with asp.net 2.0 roles management.</p> <p>here's a screen shot of the screen :</p> <p><a href="http://lh6.google.com/oooussama/R1Av1Est1KI/AAAAAAAAADs/e_MIyx4QPK8/bct1292"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="160" alt="bct-129" src="http://lh5.google.com/oooussama/R1Av10st1LI/AAAAAAAAAD0/EcNfb_0mmSE/bct129_thumb" width="243" border="0" /></a> <br />in this case we use numbers for roles 1, 2, 3 and Administrator</p> <p><a href="http://lh4.google.com/oooussama/R1Av2kst1MI/AAAAAAAAAD8/0ZQPO6m24Ls/image2"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="96" alt="image" src="http://lh5.google.com/oooussama/R1Av20st1NI/AAAAAAAAAEE/K6fyoXyruXQ/image_thumb" width="234" border="0" /></a> <br />1. Code for binding the combobox</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> BindAllRoles()<br />{<br /> <span style="color: #0000ff">this</span>.DropDownList1.DataSource = Roles.GetAllRoles();<br /> <span style="color: #0000ff">this</span>.DropDownList1.DataBind();<br />}</pre><br /></div><br /><br /><p>2. Code for Binding the Grid: the grid only contains the roles the use is in.</p><br /><br /><div><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> BearCatRoles<br /> {<br /> <span style="color: #0000ff">private</span> <span style="color: #0000ff">string</span> mRoleName;<br /><br /> <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> RoleName<br /> {<br /> get { <span style="color: #0000ff">return</span> mRoleName; }<br /> set { mRoleName = <span style="color: #0000ff">value</span>; }<br /> }<br /> <br /> }</pre><br /></div><br /><br /><div><br /> <div><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> BindRolesForUser()<br /> {<br /> <span style="color: #0000ff">string</span>[] roleslist = Roles.GetRolesForUser(<span style="color: #006080">"the user name goes here"</span>);<br /> <span style="color: #0000ff">int</span> i = 0;<br /> BearCatRoles br;<br /> List<BearCatRoles> lstbr = <span style="color: #0000ff">new</span> List<BearCatRoles>();<br /><br /> <span style="color: #0000ff">foreach</span> (<span style="color: #0000ff">string</span> brole <span style="color: #0000ff">in</span> roleslist)<br /> {<br /> br = <span style="color: #0000ff">new</span> BearCatRoles();<br /> br.RoleName = brole;<br /> lstbr.Add(br);<br /> }<br /> <span style="color: #0000ff">this</span>.GridView1.DataSource = lstbr;<br /> <span style="color: #0000ff">this</span>.GridView1.DataBind();<br /><br /> }</pre><br /> </div><br /></div><br /><br /><pre style="font-size: 10px; font-family: verdana">in The code above:<br /><br /><br />we have a class called BearCatRoles (BearCat is a specific entity, <br />to not confuse it with roles. the class is used to bind the grid<br /> to a Generic list List<BearCatRoles><br />for the BindRolesForUser() function : <br /> 1. we get the roles list for the speicific user<br /> 2. we loop through the array of roles, and fill a list of the BearCatRoles Class, then bind our grid.<br /> 3. What is necessary is to decide where to bring the userName from.<br /> For the button's click event, here's the code:</pre><br /><br /><div><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">if</span> (Roles.FindUsersInRole(<span style="color: #0000ff">this</span>.DropDownList1.SelectedItem.Text, <span style="color: #006080">"user name goes herer"</span>).Length == 0)<br /> Roles.AddUserToRole(<span style="color: #0000ff">this</span>.HiddenField1.Value, <span style="color: #0000ff">this</span>.DropDownList1.SelectedItem.Text);<br /> BindRolesForUser();</pre><br /></div><br /><br /><p>For the gridview's delete command, here's the code:</p><br /><br /><div><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> GridView1_RowCommand(<span style="color: #0000ff">object</span> sender, GridViewCommandEventArgs e)<br /> {<br /> <span style="color: #0000ff">if</span> (e.CommandName == <span style="color: #006080">"Delete"</span>)<br /> {<br /> Roles.RemoveUserFromRole(<span style="color: #0000ff">this</span>.HiddenField1.Value, e.CommandArgument.ToString());<br /> BindRolesForUser();<br /> }<br /> }</pre><br /></div><br /><br /><p>Most important Lines in this module:</p><br /><br /><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">if</span> (Roles.FindUsersInRole(<span style="color: #0000ff">this</span>.DropDownList1.SelectedItem.Text, <span style="color: #006080">"user name goes herer"</span>).Length == 0)<br /> Roles.AddUserToRole(<span style="color: #0000ff">this</span>.HiddenField1.Value, <span style="color: #0000ff">this</span>.DropDownList1.SelectedItem.Text);</pre><br /></div><br /><br /><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">Roles.RemoveUserFromRole(<span style="color: #0000ff">this</span>.HiddenField1.Value, e.CommandArgument.ToString());</pre><br /></div><br /><br /><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">string</span>[] roleslist = Roles.GetRolesForUser(<span style="color: #006080">"the user name goes here"</span>);</pre><br /></div><br /><br /><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">this</span>.DropDownList1.DataSource = Roles.GetAllRoles();</pre><br /></div><br /><br /><p> </p><br /><br /><p>Here's the markup:</p><br /><br /><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff"><</span><span style="color: #800000">asp:DropDownList</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="DropDownList1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="226px"</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">asp:DropDownList</span><span style="color: #0000ff">></span><br /><span style="color: #0000ff"><</span><span style="color: #800000">asp:Button</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="Button1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">OnClick</span><span style="color: #0000ff">="Button1_Click"</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="Add Role For User"</span> <span style="color: #0000ff">/></span><br /><span style="color: #0000ff"><</span><span style="color: #800000">asp:GridView</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="GridView1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">CellPadding</span><span style="color: #0000ff">="4"</span> <span style="color: #ff0000">ForeColor</span><span style="color: #0000ff">="#333333"</span> <span style="color: #ff0000">GridLines</span><span style="color: #0000ff">="None"</span><br /> <span style="color: #ff0000">OnRowCommand</span><span style="color: #0000ff">="GridView1_RowCommand"</span> <span style="color: #ff0000">OnSelectedIndexChanged</span><span style="color: #0000ff">="GridView1_SelectedIndexChanged"</span><br /> <span style="color: #ff0000">OnRowDeleting</span><span style="color: #0000ff">="GridView1_RowDeleting"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">Columns</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">asp:LinkButton</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="LinkButton1"</span> <span style="color: #ff0000">CommandName</span><span style="color: #0000ff">="Delete"</span> <span style="color: #ff0000">CommandArgument</span><span style="color: #0000ff">='<%# Eval("RoleName") %>'</span><br /> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span><span style="color: #0000ff">></span>Delete<span style="color: #0000ff"></</span><span style="color: #800000">asp:LinkButton</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ItemTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">asp:TemplateField</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">Columns</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">FooterStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="#5D7B9D"</span> <span style="color: #ff0000">Font-Bold</span><span style="color: #0000ff">="True"</span> <span style="color: #ff0000">ForeColor</span><span style="color: #0000ff">="White"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">RowStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="#F7F6F3"</span> <span style="color: #ff0000">ForeColor</span><span style="color: #0000ff">="#333333"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">PagerStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="#284775"</span> <span style="color: #ff0000">ForeColor</span><span style="color: #0000ff">="White"</span> <span style="color: #ff0000">HorizontalAlign</span><span style="color: #0000ff">="Center"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">SelectedRowStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="#E2DED6"</span> <span style="color: #ff0000">Font-Bold</span><span style="color: #0000ff">="True"</span> <span style="color: #ff0000">ForeColor</span><span style="color: #0000ff">="#333333"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">HeaderStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="#5D7B9D"</span> <span style="color: #ff0000">Font-Bold</span><span style="color: #0000ff">="True"</span> <span style="color: #ff0000">ForeColor</span><span style="color: #0000ff">="White"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">EditRowStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="#999999"</span> <span style="color: #0000ff">/></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">AlternatingRowStyle</span> <span style="color: #ff0000">BackColor</span><span style="color: #0000ff">="White"</span> <span style="color: #ff0000">ForeColor</span><span style="color: #0000ff">="#284775"</span> <span style="color: #0000ff">/></span><br /><span style="color: #0000ff"></</span><span style="color: #800000">asp:GridView</span><span style="color: #0000ff">></span></pre><br /></div><br /><br /><p>and Finally: in the web.config, concerning the roles, the following need to be defined:</p><br /><br /><div><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff"><</span><span style="color: #800000">roleManager</span> <span style="color: #ff0000">enabled</span><span style="color: #0000ff">="true"</span> <span style="color: #0000ff">/></span></pre><br /></div><br /><br /><p>Comments are always welcome</p> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com1tag:blogger.com,1999:blog-27388403.post-85535051033131046002007-11-26T02:29:00.001-08:002007-12-07T10:43:01.608-08:00An easy and clean way to use ajax tab container, tab panels, and user controls, to make a great multi-tab form<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script><script type="text/javascript"><br /><br /><br /><br /><br /><br /><br /><br />_uacct = "UA-3053766-2";<br />urchinTracker();</script> <p>Setting up the navigation and user Interface</p> <p>say we have a form, with asp.net 2.0. we need to allow the user to enter his 1. personnal information, 2. Professional information, 3. Contact Information, and finally, his 4. professional experience in the form of a list.</p> <div style="visibility: hidden">asp.net 2.0 ajax 1.0 C# user controls properties</div> <p>I. first we start by setting up the ajax tabs, to follow the pattern we set above. </p> <p></p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 239px; background-color: #f4f4f4"> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; height: 212px; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff"><</span><span style="color: #800000">ajaxToolkit:TabContainer</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="tbCandidate"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ActiveTabIndex</span><span style="color: #0000ff">="0"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ajaxToolkit:TabPanel</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="step1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="Personnal Information"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ContentTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ContentTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ajaxToolkit:TabPanel</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ajaxToolkit:TabPanel</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="TabPanel1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="Professional Information"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ContentTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ContentTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ajaxToolkit:TabPanel</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ajaxToolkit:TabPanel</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="TabPanel2"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="Contact Information"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ContentTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ContentTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ajaxToolkit:TabPanel</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ajaxToolkit:TabPanel</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="TabPanel3"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">HeaderText</span><span style="color: #0000ff">="Professional Experience"</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">ContentTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ContentTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"><</span><span style="color: #800000">HeaderTemplate</span><span style="color: #0000ff">></span><br /> Experience<br /> <span style="color: #0000ff"></</span><span style="color: #800000">HeaderTemplate</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ajaxToolkit:TabPanel</span><span style="color: #0000ff">></span><br /> <span style="color: #0000ff"></</span><span style="color: #800000">ajaxToolkit:TabContainer</span><span style="color: #0000ff">></span></pre><br /></div><br /><br /><p><a href="http://lh4.google.com/oooussama/R0qunEst1CI/AAAAAAAAACs/HPrkCuA_V_I/image%5B4%5D"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="92" alt="image" src="http://lh4.google.com/oooussama/R0quoEst1DI/AAAAAAAAAC0/dyOygIKY5ps/image_thumb%5B2%5D" width="578" border="0" /></a></p><br /><br /><p>II. Now, let's create a user controls for each step, this will help us organize our tabs content, as well as keep code somewhat clean and organized.</p><br /><br /><p><a href="http://lh3.google.com/oooussama/R0quo0st1EI/AAAAAAAAAC8/qvu7rLiFaZU/image%5B7%5D"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="116" alt="image" src="http://lh5.google.com/oooussama/R0quqUst1FI/AAAAAAAAADE/vrtG-W95gzw/image_thumb%5B3%5D" width="232" border="0" /></a> </p><br /><br /><p>The 4 user controls above are empty. we will place each one in its own tab. for the DataEntryControls folder, we will look at it later on.</p><br /><br /><p><a href="http://lh5.google.com/oooussama/R0qurUst1GI/AAAAAAAAADM/1h5eFzUAGOw/image%5B13%5D"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="153" alt="image" src="http://lh5.google.com/oooussama/R0qusUst1HI/AAAAAAAAADU/4Rx2QfSjlIs/image_thumb%5B7%5D" width="641" border="0" /></a> </p><br /><br /><p>III. Next, we will start by putting up the controls inside the user controls, which will set up our data entry screens. (for the sake of simplicity, we will have reduced Number of fields, 2 to 3 by user control, by tab). <br /> <br />Personnal Information :</p><br /><br /><p><a href="http://lh6.google.com/oooussama/R0qutkst1II/AAAAAAAAADc/Ejp7QVupzeY/image%5B27%5D"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="177" alt="image" src="http://lh5.google.com/oooussama/R0quuUst1JI/AAAAAAAAADk/8qRbXM7qSSs/image_thumb%5B17%5D" width="700" border="0" /></a></p> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com2tag:blogger.com,1999:blog-27388403.post-27556761005729436202007-11-23T16:02:00.003-08:002007-11-30T08:03:30.723-08:00A great site for starter kit databases :<p><a href="http://www.databaseanswers.org/" target="_blank">Database answers</a> , it's a company which has chosen to offer, online, over 200 database schemas (mostly proven and applied in production) on the net.</p> <p>to go directly to the schemas, here's the link: <a href="http://www.databaseanswers.org/data_models/index.htm" target="_blank">Free Database Models Page</a> .</p> <p>I personnally have used two schemas for stock management and invoicing, and it worked great. I was able to provide solutions to my client, write from the database schemas, modified and customized to the application needs of course.</p> <p>enjoy, and avoid reinventing the wheel!</p> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com1tag:blogger.com,1999:blog-27388403.post-44086180408933057212007-11-23T16:02:00.001-08:002007-11-26T05:08:25.943-08:00ASP.NET 2.0 and up : RequiredField Validator and DropDownList<p>Simple: to validate a dropdownlist, the following is required:</p> <p>1. AppendDataBoundItems="true" (this property allows us to add static items to the databound collection)</p> <p>2. Have an item that has a value of 0 : </p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 36px; background-color: #f4f4f4"> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff"><</span><span style="color: #800000">asp:ListItem</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="Please select an item"</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">="0"</span> <span style="color: #ff0000">Selected</span><span style="color: #0000ff">="true"</span> <span style="color: #0000ff">/></span></pre><br /></div><br /><br /><p>3. Add a required field validator with the property "InitialValue" set to 0.</p><br /><br /><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; height: 51px; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff"><</span><span style="color: #800000">asp:RequiredFieldValidator</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">id</span><span style="color: #0000ff">="RequiredDropDown"</span> <br /><span style="color: #ff0000">ControlToValidate</span><span style="color: #0000ff">="DropDownList1"</span> <span style="color: #ff0000">InitialValue</span><span style="color: #0000ff">="0"</span> <span style="color: #ff0000">ErrorMessage</span><span style="color: #0000ff">="Please select an Item"</span> <span style="color: #0000ff">/></span></pre><br /></div><br /><br /><p>Here's the complete Code Listing</p><br /><br /><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 99.5%; cursor: text; max-height: 250px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 191px; background-color: #f4f4f4"><br /> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:DropDownList</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="ddlPhases"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">DataSourceID</span><span style="color: #0000ff">="sqldatasource1"</span> <span style="color: #ff0000">Width</span><span style="color: #0000ff">="183px"</span></pre><br /><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 2:</span> <span style="color: #ff0000">DataTextField</span><span style="color: #0000ff">="Phase"</span> <span style="color: #ff0000">DataValueField</span><span style="color: #0000ff">="PhaseID"</span> <span style="color: #ff0000">AppendDataBoundItems</span><span style="color: #0000ff">="true"</span><span style="color: #0000ff">></span></pre><br /><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 3:</span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:ListItem</span> <span style="color: #ff0000">Text</span><span style="color: #0000ff">="Select a phase"</span> <span style="color: #ff0000">Value</span><span style="color: #0000ff">="0"</span> <span style="color: #0000ff">/></span></pre><br /><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 4:</span> <span style="color: #0000ff"></</span><span style="color: #800000">asp:DropDownList</span><span style="color: #0000ff">></span></pre><br /><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 5:</span>  </pre><br /><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 6:</span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:RequiredFieldValidator</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="RequiredFieldValidator1"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ControlToValidate</span><span style="color: #0000ff">="ddlPhases"</span></pre><br /><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 7:</span> <span style="color: #ff0000">Display</span><span style="color: #0000ff">="Dynamic"</span> <span style="color: #ff0000">InitialValue</span><span style="color: #0000ff">="0"</span> <span style="color: #ff0000">ErrorMessage</span><span style="color: #0000ff">="Pleas Select a Phase"</span> <span style="color: #0000ff">/></span></pre><br /><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 8:</span>  </pre><br /><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 9:</span> <span style="color: #0000ff"><</span><span style="color: #800000">asp:SqlDataSource</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">="sourcePhases"</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">="server"</span> <span style="color: #ff0000">ConnectionString</span><span style="color: #0000ff">="<%$ ConnectionStrings:CnString %>"</span></pre><br /><br /> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 10:</span> <span style="color: #ff0000">SelectCommand</span><span style="color: #0000ff">="Select PhaseID, Phase From Phase"</span> <span style="color: #0000ff">/></span></pre><br /> </div><br /></div><br /><style type="text/css"><br /><br /><br /><br /><br /><br /><br /><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style><style type="text/css"><br /><br /><br /><br /><br /><br /><br /><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }</style> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com2tag:blogger.com,1999:blog-27388403.post-59068107910622337272007-11-23T09:53:00.001-08:002007-11-23T09:55:50.065-08:00asp.net: DropDownList and SQLDataSource In a User Control<p>this is a great way to reduce code in an asp.net form. using a user control, which encapsulates all the functionality of the dropdownlist, including the data binding (sqldatastource or objectdatasource).</p> <p>here's the sample code for the ascx file:</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> <%@ Control Language=<span style="color: #006080">"C#"</span> AutoEventWireup=<span style="color: #006080">"true"</span> CodeFile=<span style="color: #006080">"ddlPhaseEnglish.ascx.cs"</span> Inherits=<span style="color: #006080">"Controls_Lists_ddlPhaseEnglish"</span> %></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 2:</span> <asp:DropDownList ID=<span style="color: #006080">"ddlPhases"</span> runat=<span style="color: #006080">"server"</span> DataSourceID=<span style="color: #006080">"sqldatasource1"</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 3:</span> Width=<span style="color: #006080">"183px"</span> DataTextField=<span style="color: #006080">"Phase"</span> DataValueField=<span style="color: #006080">"PhaseID"</span> AppendDataBoundItems=<span style="color: #006080">"true"</span>></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 4:</span> <asp:ListItem Text=<span style="color: #006080">"Select a phase"</span> Value=<span style="color: #006080">"0"</span> /></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 5:</span> </asp:DropDownList></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 6:</span> </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 7:</span> <asp:SqlDataSource ID=<span style="color: #006080">"sourcePhases"</span> runat=<span style="color: #006080">"server"</span> ConnectionString=<span style="color: #006080">"<%$ ConnectionStrings:CnString %>"</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 8:</span> SelectCommand=<span style="color: #006080">"Select PhaseID, Phase From Phase"</span>></asp:SqlDataSource></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 9:</span> </pre></div></div><br /><p>until now, it's all normal. what we add to make it the user control a DropDownList is a property to the ascx.cs file of this user control for the code behind (ascx.cs) file:</p><br /><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><br /><div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> <span style="color: #0000ff">public</span> String SelectedValue</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 2:</span> {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 3:</span> get { <span style="color: #0000ff">return</span> <span style="color: #0000ff">this</span>.ddlPhase.SelectedValue; }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 4:</span> set { <span style="color: #0000ff">this</span>.ddlPhase.SelectedValue = <span style="color: #0000ff">value</span>; }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 5:</span> }</pre></div></div><br /><p>This property gives access to the dropdownlist, directly from the user control. Combining all these (the property SelectedValue in the code behind file and the ascx, we can have the following two line to define are dropdownlist:</p><br /><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><br /><div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 1:</span> <%@ Register Src=<span style="color: #006080">"Controls/Lists/ddlPhase.ascx"</span> TagName=<span style="color: #006080">"ddlPhase"</span> TagPrefix=<span style="color: #006080">"uc8"</span> %></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060"> 2:</span> </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060"> 3:</span> <uc8:ddlPhase ID=<span style="color: #006080">"DdlPhase1"</span> runat=<span style="color: #006080">"server"</span> /></pre></div></div><pre class="csharpcode"> </pre><br /><style type="text/css">.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: consolas, "Courier New", courier, monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br />.csharpcode pre { margin: 0em; }<br />.csharpcode .rem { color: #008000; }<br />.csharpcode .kwrd { color: #0000ff; }<br />.csharpcode .str { color: #006080; }<br />.csharpcode .op { color: #0000c0; }<br />.csharpcode .preproc { color: #cc6633; }<br />.csharpcode .asp { background-color: #ffff00; }<br />.csharpcode .html { color: #800000; }<br />.csharpcode .attr { color: #ff0000; }<br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br />.csharpcode .lnum { color: #606060; }<br /></style><br /><br /><br />the above code is a lot cleaner and developer friendly than having the sqldatasource syntax included in every page. This method is just simpler than using a custom control, although the ideal is always a custom control in the bin folder.<br /><p>Here's a screen shot of what the dropdownlists folder looks like in one of the applications where this technique is applied :</p><br /><p><a href="http://lh5.google.com/oooussama/R0cTpEst08I/AAAAAAAAAB8/JmmxMVdwBtU/image%5B2%5D"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="244" alt="image" src="http://lh4.google.com/oooussama/R0cTp0st09I/AAAAAAAAACE/AU7VpZDaRq8/image_thumb" width="156" border="0"></a> <br>I hope this helps. Regards to web developpers</p> oudiniahttp://www.blogger.com/profile/02003241742069776316noreply@blogger.com1