PC Review


Reply
Thread Tools Rating: Thread Rating: 3 votes, 2.33 average.

Combo box in form

 
 
Jason
Guest
Posts: n/a
 
      11th Jun 2010
Hi,
How do I rerefence my combobox in my VB code behind. It's sitting in an ASP
formview.

When it is outside the formview my code behind works like this:
Private Sub cboCurrency_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cboCurrency.DataBound
cboCurrency.SelectedIndex =
cboCurrency.Items.IndexOf(cboCurrency.Items.FindByText("GBP"))
End Sub

When I put the combo inside the formview it says "cboCUrrency is not declared"

Thanks for your help
Regards,
fidl

 
Reply With Quote
 
 
 
 
Zhi-Qiang Ni[MSFT]
Guest
Posts: n/a
 
      15th Jun 2010
Hi fidl,

When the server control is placed in some DataControl's template, the
code-behind server event handler of the control should be bound with every
instance of each DataControl's row instead of single one. In this function,
we need to find the current instance of the ComboBox by the sender
parameter and convert it to ComboBox type. In the same time, we have to
bind every ComboBox's OnDataBound event explicitly in the HTML tag.

For example, below code is to describe how to bind a DropDownList's
DataBound event with a function and the DropDownList is placed in a
GridView's template.

.aspx file
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID"
InsertVisible="False" ReadOnly="True"
SortExpression="ID" />
<asp:TemplateField HeaderText="Field1"
SortExpression="Field1">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("Field1") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("Field1") %>'></asp:Label>
<aspropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1"
DataTextField="ID" DataValueField="Field1"
OnDataBound="DropDownList1_DataBound">
</aspropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
.aspx.vb file
Protected Sub DropDownList1_DataBound(ByVal sender As Object, ByVal e
As EventArgs) 'Handles DropDownList1.DataBound
Dim ddl As DropDownList = CType(sender, DropDownList)
ddl.SelectedIndex = 2
End Sub

--
Sincerely,
Zhi-Qiang Ni
Microsoft Online Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================

 
Reply With Quote
 
Jason
Guest
Posts: n/a
 
      22nd Jun 2010
Thanks for your excellent reply Zhi-Quiang

I'm still having troubles however. My Combo box is supposed to be a control
parameter for the form's datasource.
I think maybe this isn't possible because it tries to build the datasource
before the control exists:

<asp:UpdatePanel ID="UpdatePanel5" runat="server">
<ContentTemplate>
<asp:FormView ID="frmDashboard"
runat="server" CssClass="cssForm" DataSourceID="SqlDataSourceDash"
Style="height: 57px; width: 288px"
DefaultMode="Edit" CellPadding="10">
<EditItemTemplate>
<div style="text-align: Center;
font-weight: bold">
Dashboard</div>
<table style="text-align: right">
<tr>
<td class="styleForm">
Currency:
</td>
<td class="styleForm">
<aspropDownList
ID="cboCurrency" runat="server" DataSourceID="SqlDataSourceCurrency"
AutoPostBack="True"
DataTextField="Currency" DataValueField="CurrencyID">
</aspropDownList>
</td>
</tr>

etc.....then.....


<asp:SqlDataSource ID="SqlDataSourceCurrency"
runat="server" ConnectionString="<%$ ConnectionStrings:PADSConnectionString
%>"
SelectCommand="SELECT [CurrencyID], [Currency] FROM
[tlkpCurrency] ORDER BY [Currency]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSourceDash" runat="server"
ConnectionString="<%$ ConnectionStrings:PADSConnectionString %>"

SelectCommand="spDashboardWhereReviewUserIDCurrencyID"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter Name="UserID"
SessionField="strUserID" Type="String" />
<asp:ControlParameter
ControlID="frmDashboard$cboCurrency" Name="CurrencyID"
PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>

The error I get says that it can't find Control frmDashboard$cboCurrency for
the control source.



"Zhi-Qiang Ni[MSFT]" wrote:

> Hi fidl,
>
> When the server control is placed in some DataControl's template, the
> code-behind server event handler of the control should be bound with every
> instance of each DataControl's row instead of single one. In this function,
> we need to find the current instance of the ComboBox by the sender
> parameter and convert it to ComboBox type. In the same time, we have to
> bind every ComboBox's OnDataBound event explicitly in the HTML tag.
>
> For example, below code is to describe how to bind a DropDownList's
> DataBound event with a function and the DropDownList is placed in a
> GridView's template.
>
> .aspx file
> <asp:GridView ID="GridView1" runat="server"
> AutoGenerateColumns="False" DataKeyNames="ID"
> DataSourceID="SqlDataSource1">
> <Columns>
> <asp:BoundField DataField="ID" HeaderText="ID"
> InsertVisible="False" ReadOnly="True"
> SortExpression="ID" />
> <asp:TemplateField HeaderText="Field1"
> SortExpression="Field1">
> <EditItemTemplate>
> <asp:TextBox ID="TextBox1" runat="server" Text='<%#
> Bind("Field1") %>'></asp:TextBox>
> </EditItemTemplate>
> <ItemTemplate>
> <asp:Label ID="Label1" runat="server" Text='<%#
> Bind("Field1") %>'></asp:Label>
> <aspropDownList ID="DropDownList1" runat="server"
> DataSourceID="SqlDataSource1"
> DataTextField="ID" DataValueField="Field1"
> OnDataBound="DropDownList1_DataBound">
> </aspropDownList>
> </ItemTemplate>
> </asp:TemplateField>
> </Columns>
> </asp:GridView>
> .aspx.vb file
> Protected Sub DropDownList1_DataBound(ByVal sender As Object, ByVal e
> As EventArgs) 'Handles DropDownList1.DataBound
> Dim ddl As DropDownList = CType(sender, DropDownList)
> ddl.SelectedIndex = 2
> End Sub
>
> --
> Sincerely,
> Zhi-Qiang Ni
> Microsoft Online Support
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/en-us/subs...#notifications.
>
> MSDN Managed Newsgroup support offering is for non-urgent issues where an
> initial response from the community or a Microsoft Support Engineer within
> 2 business day is acceptable. Please note that each follow up response may
> take approximately 2 business days as the support professional working with
> you may need further investigation to reach the most efficient resolution.
> The offering is not appropriate for situations that require urgent,
> real-time or phone-based interactions. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
> ==================================================
>
> .
>

 
Reply With Quote
 
Zhi-Qiang Ni[MSFT]
Guest
Posts: n/a
 
      28th Jun 2010
Hi fidl,

The ControlParameter's ControlID property should be the DropDownList's ID
instead of its UniqueID. Please refer to my sample in this ASP.NET forum
post to describe how to previewing the Main Data in DetailsView and editing
the Detail Data in GridView by popuping the PopupControl.
http://forums.asp.net/p/1334446/2693367.aspx#2693367 .

Please let me know the test result.
--
Sincerely,
Zhi-Qiang Ni
Microsoft Online Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
filter combo box in subform withe a combo box in main form. Mike Microsoft Access Form Coding 0 18th Jan 2010 10:23 AM
requery subform combo afterupdate of main form combo nycdon Microsoft Access Form Coding 5 30th Aug 2009 01:02 PM
Combo Box on Main Form and limits Combo Box selection on the Subfo Dan H. Microsoft Access 1 18th Jun 2008 09:12 PM
Open form based on combo box value w/error message for blank combo box Ruth Microsoft Access 0 20th Apr 2007 11:00 PM
Requery a subform combo box based on a main form combo box =?Utf-8?B?ZW1pbHk=?= Microsoft Access Form Coding 2 30th Aug 2006 01:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:46 PM.