<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>C#</title><link>http://forums.asp.net/37.aspx</link><description>Discussions/Questions about the C# language. &lt;a href="http://aspadvice.com/SignUp/list.aspx?l=13&amp;c=23" target="_blank"&gt;Email List&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Using reflection to assign control value property a data column name...</title><link>http://forums.asp.net/thread/3280271.aspx</link><pubDate>Wed, 08 Jul 2009 03:55:38 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3280271</guid><dc:creator>drpcken</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3280271.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=37&amp;PostID=3280271</wfw:commentRss><description>&lt;p&gt;ok so what I found is I can return the type if it is nullable by using:&lt;/p&gt;&lt;p&gt;System.Nullable.GetUnderlyingType(field.PropertyType).FullName&lt;/p&gt;&lt;p&gt;This returns &amp;quot;System.DateTime&amp;quot; or whatever else it could be.&amp;nbsp; But if my field is not nullable then what do I do?&amp;nbsp;&amp;nbsp; I must be missing something because it has to be easier than this.&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Using reflection to assign control value property a data column name...</title><link>http://forums.asp.net/thread/3278057.aspx</link><pubDate>Tue, 07 Jul 2009 05:16:04 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3278057</guid><dc:creator>drpcken</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3278057.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=37&amp;PostID=3278057</wfw:commentRss><description>&lt;p&gt;Ok I think I just about got it using this code, but when I&amp;#39;m trying to get the type of the datacontext
property (string, datetime, int32, etc...) it returns &amp;#39;System.Runtime&amp;#39;.&lt;/p&gt;&lt;p&gt;&lt;pre name="code" class="c-sharp"&gt;DentalPlansForContact dp = new DentalPlansForContact();
                Type dbType = dp.GetType();

                foreach (PropertyInfo field in dbType.GetProperties())
                {

                    if (field.Name.ToString() == &amp;quot;id&amp;quot; || field.Name.ToString() == &amp;quot;ContactID&amp;quot;)
                    {
                        continue;
                    }
                    else
                    {
                        Type columnType = field.Name.GetType(); //Trying to get TYPE here!
                        if (columnType == typeof(DateTime))
                        {

                            RadDatePicker rdp = (RadDatePicker)Globals.FindControlRecursive(ContactTabContainer, string.Format(&amp;quot;txt{0}&amp;quot;, field.Name.ToString()));

                            field.SetValue(dp, rdp.SelectedDate, null);
                            continue;

                        }
                        if (columnType == typeof(String))
                        {
                            TextBox txt = (TextBox)Globals.FindControlRecursive(ContactTabContainer, string.Format(&amp;quot;txt{0}&amp;quot;, field.Name.ToString()));

                            field.SetValue(dp, txt.Text, null);
                            continue;
                        }
                        if (columnType == typeof(Decimal))
                        {
                            TextBox txt = (TextBox)Globals.FindControlRecursive(ContactTabContainer, string.Format(&amp;quot;txt{0}&amp;quot;, field.Name.ToString()));

                            field.SetValue(dp, txt.Text, null);
                            continue;
                        }
                        if (columnType == typeof(Int32))
                        {
                            DropDownList ddl = (DropDownList)Globals.FindControlRecursive(ContactTabContainer, string.Format(&amp;quot;ddl{0}&amp;quot;, field.Name.ToString()));

                            field.SetValue(dp, Convert.ToInt32(ddl.SelectedValue), null);
                            continue;
                        }

                    }



                }
                db.SubmitChanges();&lt;/pre&gt;&lt;br /&gt; &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;br /&gt;&lt;/p&gt;&lt;div style="overflow:hidden;position:absolute;left:-10000px;top:0px;width:1px;height:1px;" id="_mcePaste"&gt;DentalPlansForContact dp = new DentalPlansForContact();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Type dbType = dp.GetType();&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; foreach (PropertyInfo field in dbType.GetProperties()) &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (field.Name.ToString() == &amp;quot;id&amp;quot; || field.Name.ToString() == &amp;quot;ContactID&amp;quot;)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; continue;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Type columnType = field.Name.GetType(); //Trying to get TYPE here!&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (columnType == typeof(DateTime))&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; RadDatePicker rdp = (RadDatePicker)Globals.Fin&lt;div class="richText"&gt;dControlRecursive(ContactTabContainer, string.Format(&amp;quot;txt{0}&amp;quot;, field.Name.ToString()));&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; field.SetValue(dp, rdp.SelectedDate, null);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; continue;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (columnType == typeof(String))&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TextBox txt = (TextBox)Globals.FindControlRecursive(ContactTabContainer, string.Format(&amp;quot;txt{0}&amp;quot;, field.Name.ToString()));&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; field.SetValue(dp, txt.Text, null);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; continue;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (columnType == typeof(Decimal))&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TextBox txt = (TextBox)Globals.FindControlRecursive(ContactTabContainer, string.Format(&amp;quot;txt{0}&amp;quot;, field.Name.ToString()));&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; field.SetValue(dp, txt.Text, null);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; continue;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (columnType == typeof(Int32))&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DropDownList ddl = (DropDownList)Globals.FindControlRecursive(ContactTabContainer, string.Format(&amp;quot;ddl{0}&amp;quot;, field.Name.ToString()));&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; field.SetValue(dp, Convert.ToInt32(ddl.SelectedValue), null);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; continue;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; db.SubmitChanges();&lt;/div&gt;&lt;/div&gt;</description></item><item><title>Re: Using reflection to assign control value property a data column name...</title><link>http://forums.asp.net/thread/3277438.aspx</link><pubDate>Mon, 06 Jul 2009 18:57:30 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3277438</guid><dc:creator>drpcken</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3277438.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=37&amp;PostID=3277438</wfw:commentRss><description>&lt;p&gt;Thanks Rev!&amp;nbsp; I was able to figure most of this out myself the last few days.&amp;nbsp; What I was able to do is loop through my controls, get the ID, and find the corresponding field in the datacontext like so:&lt;/p&gt;&lt;p&gt;&lt;pre name="code" class="c-sharp"&gt;foreach (object innerCtrl in c.Controls)
                            {
                                if (innerCtrl is TextBox)
                                {
                                    TextBox txt = (TextBox)innerCtrl;

                                    var fld = (from v in contact.vision.GetType().GetProperties()
                                               where v.Name == txt.ID.Remove(0, 3).ToString()
                                               select v).DefaultIfEmpty().Single();

                                    if (fld != null)
                                    {
                                        txt.Text = Convert.ToString(fld.GetValue(contact.vision, null));
                                    }
                                    else
                                    {
                                        Response.Write(String.Format(&amp;quot;&amp;lt;font style=&amp;#39;color&amp;#39;red;&amp;#39;&amp;gt;Problem with field {0}&amp;lt;/font&amp;gt;&amp;lt;br /&amp;gt;&amp;quot;, txt.ID.ToString()));
                                    }
                                   

                                }
}&lt;/pre&gt;&lt;br /&gt; &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt; This works great to fill my controls in my form.&amp;nbsp; Now I&amp;#39;m trying to update and insert using LINQ and my datacontext.&amp;nbsp; I&amp;#39;m able to loop through all the properties of my DataContext object, but I&amp;#39;mhaving a problem with the SetValue method.&lt;/p&gt;&lt;p&gt;&lt;pre name="code" class="c-sharp"&gt;foreach (PropertyInfo field in contact.dental.GetType().GetProperties())  //contact.dental is my DataContext object
                {
                    
                    if (field.Name.ToString() == &amp;quot;id&amp;quot; || field.Name.ToString() == &amp;quot;ContactID&amp;quot;)
                    {
                        continue;
                    }
                    else
                    {
                        Type columnType = field.PropertyType.GetGenericArguments()[0];
                        if (columnType == typeof(DateTime))
                        {
                            RadDatePicker rdp = (RadDatePicker)Globals.FindControlRecursive(ContactTabContainer, string.Format(&amp;quot;txt{0}&amp;quot;, field.Name.ToString()));
                                
                            field.SetValue(field, rdp.SelectedDate, null);
                        }
                        //From here I want to set all the DataContext fields then do a db.SubmitChanges
                        
                    }
                    
                }&lt;/pre&gt;&lt;br /&gt; &lt;br /&gt;&lt;/p&gt;&lt;p&gt;It tells me the object does not match target type&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Any ideas?&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Using reflection to assign control value property a data column name...</title><link>http://forums.asp.net/thread/3276120.aspx</link><pubDate>Mon, 06 Jul 2009 06:40:30 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3276120</guid><dc:creator>Revdoniv</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3276120.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=37&amp;PostID=3276120</wfw:commentRss><description>&lt;p&gt;foreach (Control c in Page.Controls)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (c.GetType() == typeof(System.Web.UI.HtmlControls.HtmlForm))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach (Control formControl in c.Controls)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Type controlType = formControl.GetType();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;b&gt; if (controlType == typeof(TextBox))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //This time get Text Property&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PropertyInfo info = controlType.GetProperty(&amp;quot;Text&amp;quot;);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //formControl would be your textbox ,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //set the text property value as&amp;quot;My dynamic value&amp;quot; or say&amp;nbsp; your contact.dental.? FieldName generated from c.ID&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; info.SetValue(formControl, &amp;quot;My Own Dynamic Value&amp;quot;, null);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/b&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p&gt;Highlighted part is what you want remaining code is for just understanding.&lt;/p&gt;&lt;p&gt;See System.Reflection API .&lt;/p&gt;&lt;p&gt;Dont get confused in Reflection. just check this API ,it has good descriptive documentation so you will not find difficulties in using that.&lt;/p&gt;&lt;p&gt;Have a Great Day!&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Using reflection to assign control value property a data column name...</title><link>http://forums.asp.net/thread/3273822.aspx</link><pubDate>Fri, 03 Jul 2009 16:21:00 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3273822</guid><dc:creator>drpcken</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3273822.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=37&amp;PostID=3273822</wfw:commentRss><description>&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&amp;nbsp;I have a pretty large webform that spans about 4 ajax TabPanel tabs.&amp;nbsp;&amp;nbsp; 
Normally I just write the code to populate each control with the proper value I 
pull using LINQ to SQL.&amp;nbsp; But in my quest to learn more about c# I wondered if I 
could loop through all the controls in the form and populate them abstractly 
without having to say Control.Text = linqobject.field etc...&lt;/p&gt;
&lt;p&gt;I was discussing this with a friend of mine who said he uses reflection to 
accomplish this.&amp;nbsp; Granted ne never writes asp.net apps, mostly classes and 
libraries in VB.NET.&amp;nbsp; To start off I named my controls with the corresponding column name from the database, for example my column name from the db is &amp;#39;FirstName&amp;#39;, so I would name my corresponding textbox &amp;#39;txtFirstName&amp;#39;.&amp;nbsp; I think this will make it easier to give relation to the control and its field in the db.&amp;nbsp; &lt;/p&gt;&lt;p&gt;So I started studying reflection and understand WHAT it 
does (exposes an object&amp;#39;s types, methods, etc..), just not how it does it.&amp;nbsp; I 
started playing with it for about 3 hours last night and literally got no 
where.&amp;nbsp; My friend really tried to help but he&amp;#39;s never worked with asp.net or c# before and was lost also.&amp;nbsp; What he recommended is returning the record from linq into a collection or list, and then looping through all the controls in my form and setting the value property to the corresponding column name.&amp;nbsp; I&amp;#39;m pulling my data in using the following LINQ query:&lt;/p&gt;&lt;p&gt;&lt;pre name="code" class="c-sharp"&gt;var contact = (from company in db.Contacts
                       from plan in
                           (
                               from p in db.PlanOptionsForContacts
                               where p.ContactID == company.ContactID
                               select p
                           ).DefaultIfEmpty()
                       from dental in
                           (
                            from d in db.DentalPlansForContacts
                            where d.ContactID == company.ContactID
                            select d
                           ).DefaultIfEmpty()
                       where company.ContactID == cid
                       select new {company, plan, dental}).Single();&lt;/pre&gt;&lt;br /&gt; &lt;br /&gt; Now I HAVE to use the .Single() method to fill my company, plan, and dental objects because I&amp;#39;m still using controls that manually get filled by them.&amp;nbsp; Like so:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;pre name="code" class="c-sharp"&gt;txtCompanyName.Text = contact.company.CompanyName;&lt;/pre&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; But when I use the .Single() method, it makes my contact object not IEnuermable anymore (right??), therefore I can&amp;#39;t GetType().GetField() each contact object to return the fieldname.&amp;nbsp; At this point I&amp;#39;m at a lost.&amp;nbsp; I can vision what I want to do but have no idea how to get there. Something like:&lt;/p&gt;&lt;p&gt;&lt;pre name="code" class="c-sharp"&gt;foreach (Control c in Controls)
        {

            if (c.GetType() == typeof(TextBox))
            {
                c.Text = contact.dental.? //FieldName generated from c.ID

                
            }
        }&lt;/pre&gt;&lt;br /&gt; How can I accomplish this?&amp;nbsp; Sorry if the question is vague, I&amp;#39;m exhausted :)&amp;nbsp; Thank you!&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description></item></channel></rss>