I have DetailsView Template control containing a Label.
<ItemTemplate>
<asp:Label ID="Label_AssemblyPart" runat="server" Text='<%# Bind("AssemblyPart") %>'></asp:Label>
</ItemTemplate>
If I bind an SQLDataSource to the DetailsView in ASP Markup the DetailsView1_OnDataBound routine does not fire on Page_Load which is the correct behavior.
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:inventory_v2ConnectionString %>"
SelectCommand="SELECT Part_Catalog.ID,
Part_Catalog.OEMPartCode,
Part_Catalog.PartCode2,
Part_Catalog.UsedByOEM,
Models_OEMs.Manufacturer AS JoinedUsedByOEM,
Part_Catalog.ItemType,
Part_ItemTypes.Type AS JoinedItemType,
Part_Catalog.GroupType,
Part_Groups.GroupType AS GroupTypeText,
Part_Groups.GroupType + ' - ' + Part_Groups.GroupName AS JoinedGroupType,
Part_Catalog.PartDesc,
Part_Catalog.PartComment,
Part_Catalog.PartCount,
Part_Catalog.PartMin,
Part_Catalog.PartActive,
Part_Catalog.MFRPartNumber,
Part_Catalog.PartCapacity,
Part_Catalog.PreTurnRequired,
Part_Catalog.AssemblyPart,
Part_Catalog.PartImage,
Part_Catalog.PartImage2,
Part_Catalog.NonInventoryPart,
Part_Catalog.CreatedByUser,
Part_Catalog.LastModifiedDate
FROM Part_Catalog INNER JOIN
Models_OEMs ON Part_Catalog.UsedByOEM = Models_OEMs.ID INNER JOIN
Part_Groups ON Part_Catalog.GroupType = Part_Groups.ID INNER JOIN
Part_ItemTypes ON Part_Catalog.ItemType = Part_ItemTypes.ID
WHERE (Part_Catalog.ID = @ID)"
OnUpdating="SqlDataSource2_Updating"
DeleteCommand="DELETE FROM [Part_Catalog] WHERE [ID] = @ID"
InsertCommand=""
UpdateCommand="dbo.Procedure_UpdatePartCatalog" UpdateCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="ID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
If I set the Configuration string for that markup based datasource in code in Page_Load with :
if (GridView1.SelectedIndex != -1)
{
DetailsView1.Visible = true;
DetailsView1.Focus();
SqlDataSource2.ConnectionString = ConfigurationManager.ConnectionStrings[conString].ConnectionString;
}
the DetailsView1_OnDataBound event fires and returns a null error when it looks at Label_AssemblyPart.Text.
The DetailsView_OnDataBound event shouldn't fire at all because on the first page_load the DetailsView shouldn't have any data bound to it. There is a Gridview that loads the DetailsView on the GridView_SelectedIndex_Changed event and that only occurs on a PostBack.
It looks like the act of assigning a connect String to a DataSource alone is causing a databind.
DetailsView1.DataBind()anywhere? - Rick S<emptydatatemplate>in your detailview. - Rick S