|
-
Aug 6th, 2009, 06:15 AM
#1
Thread Starter
PowerPoster
How do I populate a combobox and then select a certain item on it
Hi guys,
how can i npopulate a combobox and then autoselect an item that corresponds to its primary key. say i populate a combo with a list of occupations from my occupation table. and then for a specific person who has an occupationid as a foreign key in the people table I want to select the related combo value
-
Aug 6th, 2009, 06:56 AM
#2
Re: How do I populate a combobox and then select a certain item on it
How are you retrieving the data? The dropdownlist control can be bound, just like you'd bind a gridview or repeater; when binding the DDL, specify the DataTextField and DataValueField.
To select a certain item, if you have the user's "pre-chosen" value, then you can find it using the FindByText or FindByValue methods and then selecting Selected to true.
-
Aug 6th, 2009, 07:39 AM
#3
Thread Starter
PowerPoster
Re: How do I populate a combobox and then select a certain item on it
hi mendhak,
thanks for the reply. sorry but i forgot to mention, the dropdownlist is in a datarepeater. Please help me. I am retrieving data from a mysql database
-
Aug 6th, 2009, 08:24 AM
#4
Re: How do I populate a combobox and then select a certain item on it
Hey,
I think it might help if you were to show some code.
What are you currently doing?
Gary
-
Aug 6th, 2009, 08:34 AM
#5
Re: How do I populate a combobox and then select a certain item on it
Yes, it would help to mention that. The same rules apply, but do an e.Item.FindControl to get the dropdownlist first, cast it to type DropDownList and then bind it to your 'source', then use FindByText or FindByValue.
-
Aug 6th, 2009, 08:55 AM
#6
Thread Starter
PowerPoster
Re: How do I populate a combobox and then select a certain item on it
Hi gep13,
I have this code:
Code:
<asp:Repeater ID="GuardianRepeater"
runat="server">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="Gid" CssClass="hidden" runat="server" Text='<%#Container.DataItem("GuardianID")%>'></asp:TextBox>
<tr>
<td>Surname:</td><td><asp:TextBox ID="Surname" CssClass="surnametextbox" runat="server" Text='<%#Container.DataItem("Surname")%>' ></asp:TextBox></td><td></td>
<td>First Names:</td><td><asp:TextBox ID="Firstnames" CssClass="surnametextbox" runat="server" Text='<%#Container.DataItem("firstnames")%>' ></asp:TextBox></td> <td></td>
</tr>
<tr>
<td>ID Number:</td><td><asp:TextBox ID="idnumber" runat="server" CssClass="surnametextbox" Text='<%#Container.DataItem("IDNumber")%>' ></asp:TextBox></td> <td></td>
<td>Cell:</td><td><asp:TextBox ID="cellphone" runat="server" CssClass="surnametextbox" Text='<%#Container.DataItem("cell")%>' ></asp:TextBox></td> <td></td>
</tr>
<tr>
<td>Tel(Work):</td><td><asp:TextBox ID="telwork" CssClass="surnametextbox" runat="server" Text='<%#Container.DataItem("Tel_Work")%>' ></asp:TextBox></td><td></td>
<td>Tel(Home):</td><td><asp:TextBox ID="telhome" CssClass="surnametextbox" runat="server" Text='<%#Container.DataItem("Tel_Home")%>' ></asp:TextBox></td> <td></td>
</tr>
<tr>
<td>Fax(Work):</td><td><asp:TextBox ID="faxwork" CssClass="surnametextbox" runat="server" Text='<%#Container.DataItem("Fax_Work")%>' ></asp:TextBox></td><td></td>
<td>Fax(Home):</td><td><asp:TextBox ID="faxhome" CssClass="surnametextbox" runat="server" Text='<%#Container.DataItem("Fax_Home")%>' ></asp:TextBox></td> <td></td>
</tr>
<tr>
<td>Occupation:</td><td></td>
</tr>
<tr>
<td>Work E-Mail:</td><td><asp:TextBox ID="email" runat="server" CssClass="emailtextbox" Text='<%#Container.DataItem("email")%>' ></asp:TextBox></td><td><asp:CheckBox ID="chkCanEmail" Checked='<%#Container.DataItem("CanEmail")%>' runat="server" />Receive E-mail Correspondence on this Address</td>
</tr>
<td>Home E-Mail:</td><td><asp:TextBox ID="HomeEmail" runat="server" CssClass="emailtextbox" Text='<%#Container.DataItem("HomeEmail")%>'></asp:TextBox></td><td><asp:CheckBox ID="chkCanEmailHome" Checked='<%#Container.DataItem("CanEmailHome")%>' runat="server" />Receive E-mail Correspondence on this Address</td><tr>
</tr>
<cc1:MaskedEditExtender ID="MaskedEditExtender1" TargetControlID="telwork" Mask="(999)9999999" MessageValidatorTip="true" MaskType="Number" ErrorTooltipEnabled="true" runat="server" ></cc1:MaskedEditExtender>
<cc1:MaskedEditExtender ID="MaskedEditExtender2" TargetControlID="telhome" Mask="(999)9999999" MessageValidatorTip="true" MaskType="Number" ErrorTooltipEnabled="true" runat="server"></cc1:MaskedEditExtender>
<cc1:MaskedEditValidator ID="MaskedEditValidator1" ControlExtender="MaskedEditExtender1" ControlToValidate="telwork" TooltipMessage="Enter a Number in this format: (999)9999999" runat="server"></cc1:MaskedEditValidator>
<%-- <asp:RequiredFieldValidator ID="RfEmail" ControlToValidate="email" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>--%>
<asp:RegularExpressionValidator ID="RevEmail" ControlToValidate="email" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" runat="server" ErrorMessage="*Email must be in the format of [email protected]" Display="Dynamic" ></asp:RegularExpressionValidator>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td colspan="6" >
<hr />
</td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
as you can see all the fields are bound. I populate a dataadapter in my codebehind.
I need to add a dropdownlist inside the datarepeater and bind it as well. please help
-
Aug 6th, 2009, 11:28 AM
#7
Re: How do I populate a combobox and then select a certain item on it
Did you do what I suggested?
-
Aug 7th, 2009, 01:00 AM
#8
Thread Starter
PowerPoster
Re: How do I populate a combobox and then select a certain item on it
thanks mendhak,
will try on tuesday. Im on leave from today
-
Aug 7th, 2009, 01:47 AM
#9
Re: How do I populate a combobox and then select a certain item on it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|