Populate fields from dropdown selectionhttp://forums.asp.net/t/1277526.aspx/1?Populate+fields+from+dropdown+selectionTue, 24 Jun 2008 20:53:45 -040012775262432264http://forums.asp.net/p/1277526/2432264.aspx/1?Populate+fields+from+dropdown+selectionPopulate fields from dropdown selection <p>Hello All,</p> <p>&nbsp;I have a page that i built that the user can enter a project and its associated features and descriptions in.&nbsp; The parameters are below:</p> <font size="2">sqlCmd.Parameters.Add(</font><font color="#a31515" size="2">&quot;@dtDate&quot;</font><font size="2">, </font><font color="#2b91af" size="2">SqlDbType</font><font size="2">.DateTime).Value = strDate;</font><font size="2"> <p>sqlCmd.Parameters.Add(</font><font color="#a31515" size="2">&quot;@nvchNT&quot;</font><font size="2">, </font><font color="#2b91af" size="2">SqlDbType</font><font size="2">.NVarChar).Value = strNTUser;</p> sqlCmd.Parameters.Add(</font><font color="#a31515" size="2">&quot;@nvchProjectNm&quot;</font><font size="2">, </font><font color="#2b91af" size="2">SqlDbType</font><font size="2">.NVarChar).Value = strProjectName;</font><font size="2"> <p>sqlCmd.Parameters.Add(</font><font color="#a31515" size="2">&quot;@nvchProjectDesc&quot;</font><font size="2">, </font><font color="#2b91af" size="2">SqlDbType</font><font size="2">.NVarChar).Value = strProjectDesc;</p> sqlCmd.Parameters.Add(</font><font color="#a31515" size="2">&quot;@intOccurrenceId&quot;</font><font size="2">, </font><font color="#2b91af" size="2">SqlDbType</font><font size="2">.NVarChar).Value = strOccurrenceId;</font><font size="2"> <p>sqlCmd.Parameters.Add(</font><font color="#a31515" size="2">&quot;@nvchOccurrence&quot;</font><font size="2">, </font><font color="#2b91af" size="2">SqlDbType</font><font size="2">.NVarChar).Value = strOccurrence;</p> sqlCmd.Parameters.Add(</font><font color="#a31515" size="2">&quot;@btAutomated&quot;</font><font size="2">, </font><font color="#2b91af" size="2">SqlDbType</font><font size="2">.NVarChar).Value = bAutomated;</font><font size="2"> <p>sqlCmd.Parameters.Add(</font><font color="#a31515" size="2">&quot;@btManual&quot;</font><font size="2">, </font><font color="#2b91af" size="2">SqlDbType</font><font size="2">.NVarChar).Value = bManual;</p> sqlCmd.Parameters.Add(</font><font color="#a31515" size="2">&quot;@intStatusId&quot;</font><font size="2">, </font><font color="#2b91af" size="2">SqlDbType</font><font size="2">.Bit).Value = strStatusId;</font><font size="2"> <p>sqlCmd.Parameters.Add(</font><font color="#a31515" size="2">&quot;@nvchStatusName&quot;</font><font size="2">, </font><font color="#2b91af" size="2">SqlDbType</font><font size="2">.NVarChar).Value = strStatusName;</p> sqlCmd.Parameters.Add(</font><font color="#a31515" size="2">&quot;@nvchAssignedMembers&quot;</font><font size="2">, </font><font color="#2b91af" size="2">SqlDbType</font><font size="2">.NVarChar).Value = strAssignedMembers;</font><font size="2"> <p>sqlCmd.Parameters.Add(</font><font color="#a31515" size="2">&quot;@dtCompDate&quot;</font><font size="2">, </font><font color="#2b91af" size="2">SqlDbType</font><font size="2">.DateTime).Value = strCompDate;</font></p> <p><font size="2"></font>&nbsp;</p> <p><font size="2">basically, i have a dropdownlist ddlSearch.&nbsp; The user can select a project from the dropdown list. The list is populated from a table in the projects database</font></p> <p><font size="2">the columns are:</font></p> <p><font size="2">RequestDate(datetime), NTLogin, ProjectName, ProjectDesc, OccurenceId(int), Occurrence, Automated(bit), Manual(bit), statusId(int), StatusName, AssignedMembers, CompletionDate(datetime)</font></p> <p>I want these fields to be populated depending on which ProjectName the user chooses from the ddlSearch dropdownlist.&nbsp; Im not sure how to get those fields to populate after making a selection as i am very new. can anyone assist with coding help in C#?<font size="2"></p> </font> 2008-06-18T21:04:15-04:002435340http://forums.asp.net/p/1277526/2435340.aspx/1?Re+Populate+fields+from+dropdown+selectionRe: Populate fields from dropdown selection <p>Hi kcrewjap,</p> <p>You can try the following method.</p> <p>&lt;asp:DropDownList ID=&quot;ddlSearch &quot; runat=&quot;server&quot; Height=&quot;21px&quot; Width=&quot;74px&quot; OnSelectedIndexChanged=&quot;DropDownList2_SelectedIndexChanged&quot; AutoPostBack=&quot;True&quot;&gt;<br> &nbsp;&lt;/asp:DropDownList&gt;</p> <p>Please set property AutoPostBack=&quot;True&quot; for server control dropdownlist.</p> <p>Then you can add the event SelectedIndexChanged handler function.</p> <p>&nbsp;&nbsp;&nbsp; protected void ddlSearch_SelectedIndexChanged(object sender, EventArgs e)<br> &nbsp;&nbsp;&nbsp; {</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string ProjectName = DropDownList1.SelectedValue;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlConnection conn = new SqlConnection(strCon);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Open();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string sql = &quot;select * from TableName where ProjectName='&quot;&#43;ProjectName&#43;&quot;'&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand cmd = new SqlCommand(sql, conn);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlDataAdapter da = new SqlDataAdapter(cmd);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataSet ds = new DataSet();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; da.Fill(ds);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dgProject.DataSource = ds;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dgProject.DataBind();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Close();</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>Then you can bind the data with GridView, it wil ok.</p> <p>Let me know if I have misunderstood what you mean. <br> Thanks.<br> Hope it helps,<br> Hua Jun </p> <p>&nbsp;</p> 2008-06-20T03:56:23-04:002436799http://forums.asp.net/p/1277526/2436799.aspx/1?Re+Populate+fields+from+dropdown+selectionRe: Populate fields from dropdown selection <p>Thank you for your reply. Just a couple questions.</p> <p>1. &lt;asp:DropDownList ID=&quot;ddlSearch &quot; runat=&quot;server&quot; Height=&quot;21px&quot; Width=&quot;74px&quot; OnSelectedIndexChanged=&quot;DropDownList2_SelectedIndexChanged&quot; AutoPostBack=&quot;True&quot;&gt;<br> &nbsp;&lt;/asp:DropDownList&gt;</p> <p>Should it say DropDownList2_SelectedIndexChanged? or ddlSearch_SelectedIndexChanged?</p> <p>&nbsp;</p> <p>2.&nbsp; DataSet ds = new DataSet();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; da.Fill(ds);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dgProject.DataSource = ds;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dgProject.DataBind();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Close();</p> <p>&nbsp;where is the dgProject comming from?</p> <p>&nbsp;</p> <p>Thanks you for your help</p> 2008-06-20T16:34:06-04:002436833http://forums.asp.net/p/1277526/2436833.aspx/1?Re+Populate+fields+from+dropdown+selectionRe: Populate fields from dropdown selection <p>also im not wanting to bing this to the gridview. what i am trying to do is get the select statement to populate the textfields and checkboxes..i included the variables and the field names in my initial post.</p> <p>&nbsp;</p> <p>thanks</p> 2008-06-20T16:50:57-04:002436841http://forums.asp.net/p/1277526/2436841.aspx/1?Re+Populate+fields+from+dropdown+selectionRe: Populate fields from dropdown selection <blockquote><span class="icon-blockquote"></span> <h4><strong>kcrewjap</strong></h4> <br> <p>1. &lt;asp:DropDownList ID=&quot;ddlSearch &quot; runat=&quot;server&quot; Height=&quot;21px&quot; Width=&quot;74px&quot; OnSelectedIndexChanged=&quot;DropDownList2_SelectedIndexChanged&quot; AutoPostBack=&quot;True&quot;&gt;<br> &nbsp;&lt;/asp:DropDownList&gt;</p> <p>Should it say DropDownList2_SelectedIndexChanged? or ddlSearch_SelectedIndexChanged?</p> <p><br> </p> </blockquote> <p></p> <p>If you let the VS&nbsp; generates the event for you then basically it will generate like &quot;ddlSearch_SelectedIndexChanged&quot;..As you noticed It will just append the ID of the control to the event SelectedIndexChange.. But in that case you have mentioned it does not matter if you use DropDownList2_SelectedIndexChanged or ddlSearch_SelectedIndexChanged for as long as it will match the event handler in your code behind..&nbsp; see below</p> <p>&lt;asp:DropDownList ID=&quot;ddlSearch &quot; runat=&quot;server&quot; Height=&quot;21px&quot; Width=&quot;74px&quot; <b> OnSelectedIndexChanged=&quot;DropDownList2_SelectedIndexChanged&quot;</b> AutoPostBack=&quot;True&quot;&gt;</p> <p>if using the above declaration&nbsp; then&nbsp; event handler method should look like this below</p> <p>protected void <b>DropDownList2_SelectedIndexChanged</b>(object sender, EventArgs e)<br> { </p> <p>}&nbsp;</p> <p>Or you declare it this way</p> <p>&lt;asp:DropDownList ID=&quot;ddlSearch &quot; runat=&quot;server&quot; Height=&quot;21px&quot; Width=&quot;74px&quot; <b> OnSelectedIndexChanged=&quot;ddlSearch </b><b>_SelectedIndexChanged&quot;</b> AutoPostBack=&quot;True&quot;&gt; </p> <p>Then your event handler method should look like this below</p> <p>protected void <b>ddlSearch</b><b>_SelectedIndexChanged</b>(object sender, EventArgs e)<br> { </p> <p>} </p> <p>Hope you get it..&nbsp;</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4><strong>kcrewjap</strong></h4> <br> <p></p> <p>2.&nbsp; DataSet ds = new DataSet();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; da.Fill(ds);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dgProject.DataSource = ds;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dgProject.DataBind();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Close();</p> <p>&nbsp;where is the dgProject comming from?</p> <p><br> </p> </blockquote> <p></p> <p><b>dgProject&nbsp; </b>is the ID of your Grid control that you are using.. <br> </p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> 2008-06-20T16:54:14-04:002436854http://forums.asp.net/p/1277526/2436854.aspx/1?Re+Populate+fields+from+dropdown+selectionRe: Populate fields from dropdown selection <p></p> <blockquote><span class="icon-blockquote"></span> <h4><strong>kcrewjap </strong></h4> <br> also im not wanting to bing this to the gridview. what i am trying to do is get the select statement to populate the textfields and checkboxes..i included the variables and the field names in my initial post.<br> </blockquote> <br> <p></p> <p>What about this</p> <p>private void FillTextBoxes(string ProjectName)<br> {</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SqlConnection conn = new SqlConnection(strCon);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Open();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string sql = &quot;select * from TableName where ProjectName='&quot;&#43;ProjectName&#43;&quot;'&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand cmd = new SqlCommand(sql, conn);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlDataAdapter da = new SqlDataAdapter(cmd);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataTable dt = new DataTable();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; da.Fill(dt);<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; if (dt.Rows.Count &gt; 0)<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; {<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; TextBox1.Text= dt.Rows[0][&quot;ColumnName&quot;].TosTring(); <b>//Where column name us the Fields for your Table that you wanted to display in the TextBoxes</b><br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; TextBox2.Text= dt.Rows[0][&quot;ColumnName&quot;].TosTring();<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Close();<br> &nbsp; <br> </p> <p>}&nbsp;</p> <p>protected void ddlSearch_SelectedIndexChanged(object sender, EventArgs e)<br> {<br> <br> &nbsp;<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FillTextBoxes(DropDownList1.SelectedValue);</b><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> } <br> </p> 2008-06-20T17:00:40-04:002436910http://forums.asp.net/p/1277526/2436910.aspx/1?Re+Populate+fields+from+dropdown+selectionRe: Populate fields from dropdown selection <p>awesome. but what if you have a radiobuttonlist? how do you populate that from the database? rblStatus</p> 2008-06-20T17:28:15-04:002436946http://forums.asp.net/p/1277526/2436946.aspx/1?Re+Populate+fields+from+dropdown+selectionRe: Populate fields from dropdown selection <p></p> <blockquote><span class="icon-blockquote"></span> <h4><strong>kcrewjap</strong></h4> <br> awesome. but what if you have a radiobuttonlist? how do you populate that from the database? rblStatus<br> </blockquote> <br> <p></p> <p>Same steps</p> <p>private void FillRBL(string ProjectName)<br> {</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SqlConnection conn = new SqlConnection(strCon);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Open();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string sql = &quot;select * from TableName where ProjectName='&quot;&#43;ProjectName&#43;&quot;'&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand cmd = new SqlCommand(sql, conn);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlDataAdapter da = new SqlDataAdapter(cmd);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataTable dt = new DataTable();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; da.Fill(dt);<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; if (dt.Rows.Count &gt; 0)<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; {</p> <p><b>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RadioButtonList1.DataSource = dt;<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; RadioButtonList1.DataTextField = &quot;ColumnName&quot;; // DataTextField is where the Fields are being displayed in RBL Text<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RadioButtonList1.DataValueFieild = &quot;ColumnName&quot;; //DataValueFieild usually contains the ID of the fields<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; RadioButtonList1.DataBind();</b><br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Close();<br> &nbsp; <br> </p> <p>}&nbsp;</p> <p>protected void ddlSearch_SelectedIndexChanged(object sender, EventArgs e)<br> {<br> <br> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FillRBL</b><b>(DropDownList1.SelectedValue);</b><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> }</p> <p><br> &nbsp;</p> <p>&nbsp;</p> 2008-06-20T17:48:27-04:002437276http://forums.asp.net/p/1277526/2437276.aspx/1?Re+Populate+fields+from+dropdown+selectionRe: Populate fields from dropdown selection <p>and for a dropdownlist </p> &nbsp;i have <font size="2"></font><font size="2"> <p>ddlOccurrence.SelectedValue = dt.Rows[0][</font><font color="#a31515" size="2">&quot;Occurrence&quot;</font><font size="2">].ToString();</font></p> <p><font size="2">however it doesnt like the SelectedValue nor SelectedIndex.. which option to i put for a ddl?</font></p> <p><font size="2"></font>&nbsp;</p> <p><font size="2">Thanks for all of your time and help</p> </font> 2008-06-20T20:42:43-04:002437283http://forums.asp.net/p/1277526/2437283.aspx/1?Re+Populate+fields+from+dropdown+selectionRe: Populate fields from dropdown selection <p></p> <blockquote><span class="icon-blockquote"></span> <h4><b>kcrewjap</b></h4> <br> <p></p> <p><font size="2">ddlOccurrence.SelectedValue = dt.Rows[0][</font><font color="#a31515" size="2">&quot;Occurrence&quot;</font><font size="2">].ToString();</font></p> <p><font size="2">however it doesnt like the SelectedValue nor SelectedIndex.. which option to i put for a ddl?</font><br> <br> </p> </blockquote> <br> <p></p> <p>If you wanted to add Items in your DropDownList then have it this way</p> <p>string strItem = <font size="2">dt.Rows[0][</font><font color="#a31515" size="2">&quot;Occurrence&quot;</font><font size="2">].ToString();</font> <br> <font size="2">ddlOccurrence.Items.Add(</font>strItem);</p> <p><br> </p> 2008-06-20T20:47:24-04:002437316http://forums.asp.net/p/1277526/2437316.aspx/1?Re+Populate+fields+from+dropdown+selectionRe: Populate fields from dropdown selection <p>so let me make sure im understanding you right. the ddl that i am referring to is one that will be populated with whatever is in the database for that field when all fillprojectfields method is called.. this is not the original ddl where they select the project to populate..</p> <p>&nbsp;</p> <p>&nbsp;</p> 2008-06-20T21:14:33-04:002437320http://forums.asp.net/p/1277526/2437320.aspx/1?Re+Populate+fields+from+dropdown+selectionRe: Populate fields from dropdown selection <p></p> <blockquote><span class="icon-blockquote"></span> <h4><strong>kcrewjap</strong></h4> <br> so let me make sure im understanding you right. the ddl that i am referring to is one that will be populated with whatever is in the database for that field when all fillprojectfields method is called.. this is not the original ddl where they select the project to populate..<br> </blockquote> <br> <p></p> <p>I'm confused here.. What exactly you are trying to do? <br> </p> 2008-06-20T21:21:33-04:002437327http://forums.asp.net/p/1277526/2437327.aspx/1?Re+Populate+fields+from+dropdown+selectionRe: Populate fields from dropdown selection <p>sorry. I have a page that has a handfull of textboxes, dropdownlists, radiobuttons and checkboxlists. at the top i have a dropdownlist of ProjectNames. when the user selcts a projectname from the dropdownlist, i am trying to have the rest of the fields populated based on that selection. make sense?</p> 2008-06-20T21:28:13-04:002437350http://forums.asp.net/p/1277526/2437350.aspx/1?Re+Populate+fields+from+dropdown+selectionRe: Populate fields from dropdown selection <p>Yes i understand but you cannot assign SelectedValue and SelectedItem.Tex on DDL and RBL you need to use Items.Add method to add items on DDL and RBL based on DDL from ProjectNames... see below..<br> </p> <p>private void <b>FillDT</b>(string ProjectName)<br> {</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SqlConnection conn = new SqlConnection(strCon);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Open();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string sql = &quot;select * from TableName where ProjectName='&quot;&#43;ProjectName&#43;&quot;'&quot;;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand cmd = new SqlCommand(sql, conn);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlDataAdapter da = new SqlDataAdapter(cmd);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataTable dt = new DataTable();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; da.Fill(dt);<br> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; if (dt.Rows.Count &gt; 0)<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; {<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; TextBox1.Text= dt.Rows[0][&quot;ColumnName1&quot;].TosTring(); <b>//Where column name us the Fields for your Table that you wanted to display in the TextBoxes</b><br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; TextBox2.Text= dt.Rows[0][&quot;ColumnName2&quot;].TosTring();<br> &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; DropDownList1.Items.Add(dt.Rows[0][&quot;ColumnName3&quot;].TosTring());<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RadioButtonList1.Items.Add(dt.Rows[0][&quot;ColumnName4&quot;].TosTring());<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; CheckBoxList1.Items.Add(dt.Rows[0][&quot;ColumnName5&quot;].TosTring());<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.Close();<br> &nbsp; <br> </p> <p>}&nbsp;</p> protected void ddlSearch_SelectedIndexChanged(object sender, EventArgs e)<br> {<br> <br> &nbsp;<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FillDT(DropDownList1.SelectedValue);</b><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> } <p>Did you get it?<br> </p> 2008-06-20T21:48:31-04:002440832http://forums.asp.net/p/1277526/2440832.aspx/1?Re+Populate+fields+from+dropdown+selectionRe: Populate fields from dropdown selection <p>Hey Vincent,</p> <p>&nbsp;The textboxes fill,&nbsp; but the ddl's dont display what should be displayed from the database, they just look like im adding a new project &quot;Please Choose&quot;. any suggestions?</p> 2008-06-23T16:08:19-04:002440936http://forums.asp.net/p/1277526/2440936.aspx/1?Re+Populate+fields+from+dropdown+selectionRe: Populate fields from dropdown selection <p></p> <blockquote><span class="icon-blockquote"></span> <h4><strong>kcrewjap </strong></h4> <br> &nbsp;The textboxes fill,&nbsp; but the ddl's dont display what should be displayed from the database, they just look like im adding a new project &quot;Please Choose&quot;. any suggestions?<br> </blockquote> <p></p> <p>Post your codes here so that we can check it out... BTW does your DDL contains multiple data?if you only want to add a single value from database then use TextBox instead..<br> </p> 2008-06-23T17:03:57-04:002441371http://forums.asp.net/p/1277526/2441371.aspx/1?Re+Populate+fields+from+dropdown+selectionRe: Populate fields from dropdown selection <font color="#0000ff" size="2"> <p>Here is my code so far. i have got everything to work except one part. In the database that this project is pulled by there is a checkboxlist&nbsp;(names of people working on project) when the project is initially stored, it stores all the checkboxes&nbsp;that are checked as numbers in a string. what i would like to do is on the update page (code below) i want to comapare the checkboxlist against the database&nbsp;values adn then make the appropriate checkboxes in the list be checked or not checked according to whats in the database.&nbsp; Heres an example of how thenames are stored as a sting in the database</p> <p>&nbsp;</p> <p>column name = AssignedMemebers</p> <p>CheckboxList = cblAssignedMembers</p> <p>raw data in database = 2, 4, 5, 6&nbsp; numbers represent different checkboxes(names) checked in the cbl.</p> <p>&nbsp;</p> <p>Here is my update code so far. everything works now except the cblAssignedMembers</p> <p>&nbsp;</p> <p>Thanks</p> <p>&nbsp;</p> protected</font><font size="2"> </font><font color="#0000ff" size="2">void</font><font size="2"> ddlSearch_SelectedIndexChanged(</font><font color="#0000ff" size="2">object</font><font size="2"> sender, </font><font color="#2b91af" size="2">EventArgs</font><font size="2"> e)</font><font size="2"> <p>{</p> <p>FillProjectFields(ddlSearch.SelectedValue);</p> <p>&nbsp;</p> <p>}</p> </font><font color="#0000ff" size="2">private</font><font size="2"> </font><font color="#0000ff" size="2">void</font><font size="2"> FillProjectFields(</font><font color="#0000ff" size="2">string</font><font size="2"> strProjectName)</font><font size="2"> <p>{</p> </font><font color="#2b91af" size="2">SqlConnection</font><font size="2"> conn = </font> <font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#2b91af" size="2">SqlConnection</font><font size="2">(</font><font color="#2b91af" size="2">Conn</font><font size="2">.CLNXCnnString());</font><font size="2"> <p>conn.Open();</p> </font><font color="#0000ff" size="2">string</font><font size="2"> sql = </font><font color="#a31515" size="2">&quot;select * from tblAddProject where ProjectName='&quot;</font><font size="2"> &#43; strProjectName &#43; </font><font color="#a31515" size="2">&quot;'&quot;</font><font size="2">;</font><font size="2"> <p></font><font color="#2b91af" size="2">SqlCommand</font><font size="2"> cmd = </font> <font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#2b91af" size="2">SqlCommand</font><font size="2">(sql, conn);</p> </font><font color="#2b91af" size="2">SqlDataAdapter</font><font size="2"> da = </font> <font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#2b91af" size="2">SqlDataAdapter</font><font size="2">(cmd);</font><font size="2"></font><font color="#2b91af" size="2">DataTable</font><font size="2"> dt = </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#2b91af" size="2">DataTable</font><font size="2">();</font><font size="2"> <p>da.Fill(dt);</p> </font><font color="#0000ff" size="2">if</font><font size="2"> (dt.Rows.Count &gt; 0)</font><font size="2"> <p>{</p> <p>txtDate.Text = dt.Rows[0][</font><font color="#a31515" size="2">&quot;RequestDate&quot;</font><font size="2">].ToString();</p> txtChangeUser.Text = dt.Rows[0][</font><font color="#a31515" size="2">&quot;NTLogin&quot;</font><font size="2">].ToString();</font><font size="2"> <p>txtProjectName.Text = dt.Rows[0][</font><font color="#a31515" size="2">&quot;ProjectName&quot;</font><font size="2">].ToString();</p> txtProjectDesc.Text = dt.Rows[0][</font><font color="#a31515" size="2">&quot;ProjectDesc&quot;</font><font size="2">].ToString();</font><font size="2"> <p>ddlOccurrence.Items.Add(dt.Rows[0][</font><font color="#a31515" size="2">&quot;Occurrence&quot;</font><font size="2">].ToString());</p> </font><font color="#0000ff" size="2">if</font><font size="2">(dt.Rows[0][</font><font color="#a31515" size="2">&quot;Occurrence&quot;</font><font size="2">].ToString() == </font><font color="#a31515" size="2">&quot;Reoccurring&quot;</font><font size="2">)</font><font size="2"> <p>{</p> ddlOccurrence.SelectedValue = </font><font color="#a31515" size="2">&quot;Reoccurring&quot;</font><font size="2">; </font><font size="2"> <p>}</p> </font><font color="#0000ff" size="2">else</font><font size="2"> </font><font color="#0000ff" size="2">if</font><font size="2"> (dt.Rows[0][</font><font color="#a31515" size="2">&quot;Occurrence&quot;</font><font size="2">].ToString() == </font><font color="#a31515" size="2">&quot;One Time&quot;</font><font size="2">)</font><font size="2"> <p>{</p> ddlOccurrence.SelectedValue = </font><font color="#a31515" size="2">&quot;One Time&quot;</font><font size="2">;</font><font size="2"> <p>}</p> rblOccurrance.Items.Add(dt.Rows[0][</font><font color="#a31515" size="2">&quot;Automated&quot;</font><font size="2">].ToString());</font><font size="2"> <p>rblOccurrance.Items.Add(dt.Rows[0][</font><font color="#a31515" size="2">&quot;Manual&quot;</font><font size="2">].ToString());</p> ddlStatus.Items.Add(dt.Rows[0][</font><font color="#a31515" size="2">&quot;StatusName&quot;</font><font size="2">].ToString());</font><font size="2"></font><font color="#0000ff" size="2">if</font><font size="2"> (dt.Rows[0][</font><font color="#a31515" size="2">&quot;StatusName&quot;</font><font size="2">].ToString() == </font><font color="#a31515" size="2">&quot;New&quot;</font><font size="2">)</font><font size="2"> <p>{</p> ddlStatus.SelectedValue = </font><font color="#a31515" size="2">&quot;New&quot;</font><font size="2">;</font><font size="2"> <p>}</p> </font><font color="#0000ff" size="2">else</font><font size="2"> </font><font color="#0000ff" size="2">if</font><font size="2"> (dt.Rows[0][</font><font color="#a31515" size="2">&quot;StatusName&quot;</font><font size="2">].ToString() == </font><font color="#a31515" size="2">&quot;Assigned&quot;</font><font size="2">)</font><font size="2"> <p>{</p> ddlStatus.SelectedValue = </font><font color="#a31515" size="2">&quot;Assigned&quot;</font><font size="2">; </font><font size="2"> <p>}</p> </font><font color="#0000ff" size="2">else</font><font size="2"> </font><font color="#0000ff" size="2">if</font><font size="2"> (dt.Rows[0][</font><font color="#a31515" size="2">&quot;StatusName&quot;</font><font size="2">].ToString() == </font><font color="#a31515" size="2">&quot;Complete&quot;</font><font size="2">)</font><font size="2"> <p>{</p> ddlStatus.SelectedValue = </font><font color="#a31515" size="2">&quot;Complete&quot;</font><font size="2">;</font><font size="2"> <p>}</p> <p>cblMembersAssigned.Items.Add(dt.Rows[0][</font><font color="#a31515" size="2">&quot;AssignedMembers&quot;</font><font size="2">].ToString());</p> txtCompletionDate.Text = dt.Rows[0][</font><font color="#a31515" size="2">&quot;CompletionDate&quot;</font><font size="2">].ToString();</font><font size="2"> <p>}</p> <p>conn.Close();</p> <p>}</p> </font> 2008-06-23T20:23:24-04:002441372http://forums.asp.net/p/1277526/2441372.aspx/1?Re+Populate+fields+from+dropdown+selectionRe: Populate fields from dropdown selection <font color="#0000ff" size="2"> <p>&nbsp;</p> </font> 2008-06-23T20:23:28-04:002441429http://forums.asp.net/p/1277526/2441429.aspx/1?Re+Populate+fields+from+dropdown+selectionRe: Populate fields from dropdown selection <p>I'm not sure if this is really what you need but i hope this will give you an idea</p> Put this snippet below after conn.Close();<br> <p><br> for (int i=0; i &lt;cblMembersAssigned.Items.Count; i&#43;&#43;)<br> {<br> &nbsp;&nbsp;&nbsp; if (cblMembersAssigned.Items[i].Text = &quot;Values to compare here&quot;)<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if it's equal then check the items in the CHeckBox<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cblMembersAssigned.Items[i].Selected = true;<br> &nbsp;&nbsp;&nbsp; }<br> } <br> </p> 2008-06-23T20:48:55-04:002441435http://forums.asp.net/p/1277526/2441435.aspx/1?Re+Populate+fields+from+dropdown+selectionRe: Populate fields from dropdown selection <p>where it says &quot;Values to compare here&quot; in that string can i put &quot;1, 2, 3, 4, 5, 6&quot;??</p> 2008-06-23T20:52:25-04:00