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>
<asp
ropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1"
DataTextField="ID" DataValueField="Field1"
OnDataBound="DropDownList1_DataBound">
</asp
ropDownList>
</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/subscriptions/aa948868.aspx#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/subscriptions/aa948874.aspx
==================================================