How to load a video using a string from a database? - asp.net

I've got a website where I want to be able to generate a list of videos available on my server. Once that user selects a video, it would take them to another page where it plays the video. So far, I've got no errors on either of the pages, but nothing is showing up either :(
Here's the code for my pages:
word.aspx
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/webvideos.mdb" SelectCommand="SELECT TOP 5 * FROM [Videos] WHERE ID=#ID AND Program LIKE 'Word'">
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="ID" />
</SelectParameters>
</asp:AccessDataSource>
<asp:DataList ID="DataList1" runat="server" DataSourceID="AccessDataSource1" RepeatColumns="5">
<ItemTemplate>
<table>
<tr>
<td>
<asp:HyperLink ID="VidLink1" runat="server" Target="_blank" NavigateUrl='<%# "VideoPlayer.aspx?ID=" & Eval("ID") %>' >
<asp:Image ID="VidThumb" runat="server" ImageUrl='<%# "videos/TraningVideos/Thumbnails" & Eval("Thumbnail") %>' /></asp:HyperLink>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
And here's VideoPlayer.aspx:
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT * FROM Video WHERE ID=#ID" >
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="ID" />
</SelectParameters>
</asp:AccessDataSource>
'
width="450" height="380">
' />
<param name="autostart" value="false" />
<param name="controller" value="true" />
</object>
<ASPNetFlashVideo:FlashVideo ID="FlashVideo1" runat="server" VideoURL="http://www.youtube.com/watch?v=okHuuMbIg1E">
</ASPNetFlashVideo:FlashVideo>
<ASPNetFlashVideo:FlashVideo ID="FlashVideo2" runat="server" VideoURL='<%# "~/videos/TrainingVideos/" & Eval("Filename") %>'>
</ASPNetFlashVideo:FlashVideo>
As you can see, I've even tried using a regular youtube link for the ASPNetFlashVideo control that I've been able to add, and it hasn't been working either. Any ideas?

Related

Server Error in '/' Application. A ControlID must be specified in ControlParameter 'Product_Name'

I am new here and a beginner with APS and VB, I do have SQL experience. the problem I am having is I am trying to select two values in a VB aspx page.
one is a text box which can be types into, the other is a value which is selected from a drop downlist that looks as a table in my SQL database.
I want both values once entered and selected to be entered as a new row into another table of the same database, but I am getting the following error. and its driving me round in circles.
A ControlID must be specified in ControlParameter 'Product_Name'.
my code is as below, I suspect it is something simple that I am missing but I cannot see it for looking, can anyone help please?
<table style="width:100%;">
<tr>
<td>
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DefaultMode="Insert">
<InsertItemTemplate>
Product_Name:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="Product_Name" DataValueField="Product_Name">
</asp:DropDownList>
<ItemTemplate>
Product_Description:
<asp:TextBox ID="Product_DescriptionTextBox" runat="server" Text='<%# Bind("Product_Description") %>' />
<br />
<asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
<asp:Button ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Incident_TrackerConnectionString %>" InsertCommand="INSERT INTO [Incidents] ( [I_Product_Name], [I_Product_Description]) VALUES ( #Product_Name, #Product_Description)">
<InsertParameters>
<asp:ControlParameter Name="Product_Name" Type="String" />
<asp:Parameter Name="Product_Description" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:Incident_TrackerConnectionString %>" SelectCommand="select Product_Name from dbo.products"></asp:SqlDataSource>
</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style2"></td>
<td class="auto-style2"></td>
</tr>
<tr>
<td class="auto-style1"> </td>
<td class="auto-style1"></td>
<td class="auto-style1"></td>
</tr>
</table>
<br />
<br />
<br />
Thanks Kevin
You nee to specify the ControlID & PropertyName like this:-
<InsertParameters>
<asp:ControlParameter Name="Product_Name" ControlID="DropDownList1"
PropertyName="SelectedValue" />
</InsertParameters>
Edit:-
Okay, since you are using FormView, you need to specify it like this:-
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource2" DataTextField="Product_Name"
DataValueField="Product_Name" SelectedValue=<%# Bind('Product_Name') %>>
</asp:DropDownList>
Then , bind the InsertParameters as:-
<InsertParameters>
<asp:Parameter Name="Product_Name" Type="String" />
<asp:Parameter Name="Product_Description" Type="String" />
</InsertParameters>

Cannot Find Control ID in ControlParameter

I am trying to insert values from a textbox but I get an error that it cannot find the controlid in the controlparameter. The TextBox is inside a formview, which is inside a listview. The SqlDataSource is outside the ListView.
My InsertButton_Click Method
protected void InsertButton_Click(object sender, EventArgs e)
{
var ctrl = (Control)sender;
var formview = (FormView)ctrl.NamingContainer;
formview.ChangeMode(FormViewMode.Insert);
SectionListView.DataSource = SectionDataSource;
SectionListView.DataBind();
}
The InsertItem Template
<InsertItemTemplate>
<tr style="">
<td>
<div style="font-size: .8em;">
<asp:FormView ID="SectionFormView" runat="server" DataKeyNames="SectionItemID" DataSourceID="SectionDataSource">
<ItemTemplate>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" OnClick="InsertButton_Click" Font-Size="1.2em" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" Font-Size="1.2em" />
<asp:Label ID="SectionItemLabel" runat="server" Text="SectionItem" Font-Bold="true" Font-Size="1.2em" />
<asp:TextBox ID="SectionItemTextBox" runat="server" />
<asp:Label ID="SectionItemSubLabel" runat="server" Text="SectionItem Label" Font-Bold="true" Font-Size="1.2em" />
<asp:TextBox ID="SectionItemLabelTextBox" runat="server"/>
</ItemTemplate>
</asp:FormView>
</div>
</td>
</tr>
</InsertItemTemplate>
My SqlDataSource
<asp:SqlDataSource ID="SectionDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ORHP_Dev03182014ConnectionString %>" SelectCommand="SELECT DISTINCT SectionItem,SectionItemLabel,SectionItemID FROM Core.SectionItem_Lkup"
InsertCommand="INSERT INTO Core.SectionItem_Lkup(SectionItem, SectionItemLabel) VALUES (#SectionItem, #SectionItemLabel)">
<InsertParameters>
<asp:ControlParameter ControlID="SectionItemTextBox" Name="SectionItem" PropertyName="Text" />
<asp:ControlParameter ControlID="SectionItemLabelTextBox" Name="SectionItemLabel" PropertyName="Text" />
</InsertParameters>
</asp:SqlDataSource>
When you want to use the child controls as control parameters, you need to use the qualified id as control id. Try changing the SQL data source as below
<asp:SqlDataSource ID="SectionDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ORHP_Dev03182014ConnectionString %>" SelectCommand="SELECT DISTINCT SectionItem,SectionItemLabel,SectionItemID FROM Core.SectionItem_Lkup"
InsertCommand="INSERT INTO Core.SectionItem_Lkup(SectionItem, SectionItemLabel) VALUES (#SectionItem, #SectionItemLabel)">
<InsertParameters>
<asp:ControlParameter ControlID="SectionFormView$SectionItemTextBox" Name="SectionItem" PropertyName="Text" />
<asp:ControlParameter ControlID="SectionFormView$SectionItemLabelTextBox" Name="SectionItemLabel" PropertyName="Text" />
</InsertParameters>
</asp:SqlDataSource>

System.Data.OleDb.OleDbException on DataSource/DataList

I'm relatively new, so it shouldn't be too surprising I haven't seen the error before, but when I try to run a page, I get the error System.Data.OleDb.OleDbException: IErrorInfo.GetDescription failed with E_FAIL(0x80004005)
Here is the code for that page:
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/webvideos.mdb" SelectCommand="SELECT * FROM [Docs] WHERE Section = 1">
</asp:AccessDataSource>
<asp:AccessDataSource ID="AccessDataSource2" runat="server"
DataFile="~/App_Data/webvideos.mdb" SelectCommand="SELECT * FROM [Docs] WHERE Section = 2">
</asp:AccessDataSource>
<asp:AccessDataSource ID="AccessDataSource3" runat="server"
DataFile="~/App_Data/webvideos.mdb" SelectCommand="SELECT * FROM [Docs] WHERE Section = 3">
</asp:AccessDataSource>
<asp:AccessDataSource ID="AccessDataSource4" runat="server"
DataFile="~/App_Data/webvideos.mdb" SelectCommand="SELECT * FROM [Docs] WHERE Section = 4">
</asp:AccessDataSource>
<h2>Benefits Information</h2>
<br />
<asp:Label ID="OpenEnrollmentHeader" runat="server" Text="Open Enrollment" CssClass="BenefitsHeaderStyle" />
<asp:DataList ID="DataList1" runat="server" CellPadding="10"
DataSourceID="AccessDataSource1">
<ItemTemplate>
<asp:HyperLink ID="OpenEnrollmentDocs" runat="server" Text='<%# Eval("Label") %>'
NavigateUrl='<%# "~/docs/HRDocs/" & Eval("Filename") %>' />
</ItemTemplate>
</asp:DataList>
<br />
I can see that it must have something to do with my data sources or the Datalist control, but I have no idea what. Any ideas? I can tell you that there is one result in the first select statement and none, perhaps, in the others.
Your code contains a reserved word, ill try and pick it out now

WhereParameter is not working for dropdownlist

My Table structure
Courses
Id
Description
Subjects
Id
Description
Courses (Relation to Courses table).
My code as follows
td>
<asp:DropDownList ID="ddlCourses" runat="server" DataSourceID="LinqCourses"
DataTextField="Description" DataValueField="Id"/>
<asp:LinqDataSource ID="LinqCourses" runat="server"
ContextTypeName= "DataAccess.SchoolStudyDataContext" Select="new (Description, Id)"
TableName="Courses" />
</td>
<td align="left" valign="top" class="style5" style="width: 124px">
<asp:DropDownList ID="ddlSubjects" runat="server" DataSourceID="LinqSubjects"
DataTextField="Description" DataValueField="Id"/>
<asp:LinqDataSource ID="LinqSubjects" runat="server"
ContextTypeName= "DataAccess.SchoolStudyDataContext" Select="new (Description,Courses,Id)"
TableName="Subjects" Where="Courses == #Id" />
<WhereParameters>
asp:ControlParameter ControlID="ddlCourses" Name="Id"
PropertyName="SelectedValue" Type="Int32" />
</WherePrameters>
<asp:DropDownList ID="ddlCourses" runat="server" DataSourceID="SqlDataSource1"
DataTextField="Description" DataValueField="Id"/>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>"
SelectCommand="SELECT [Description],[Courses],[Id] FROM [table_name] WHERE ([Courses ] = #Courses ) ">
<SelectParameters>
<asp:Parameter Name="Courses" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
This is not a exact answer but this might help i guess
Your Where Property is wrong. Change this (==):
Where="Courses == #Id" />
To this (=):
Where="Courses = #Id" />
Source: MSDN

Cannot get/use ControlParameter from GridView in a TemplateField SELECT statement

I have a simple GridView (with an ID of 'GridViewAttribs') which displays some values from a database.
Within my GridViewAttribs I wish to have a (nested?) ListView but for some reason I cannot use the asp:ControlParameter ControlID="GridViewAttribs" PropertyName as no results are returned in my (nested) ListView.
If I do NOT use the ControlParameter and hardcode my SELECT statement for the ListView, everything works as expected.
Here's my code:
<asp:SqlDataSource ID="SqlDataSourceAttribHeadings" runat="server"
ConnectionString="<%$ ConnectionStrings:customer_support_devConnectionString %>"
ProviderName="<%$ ConnectionStrings:customer_support_devConnectionString.ProviderName %>"
SelectCommand="SELECT equipment_attrib_heading_id, equipment_model_id, equipment_attrib_name FROM equipment_new_attrib_headings WHERE (equipment_model_id = #equipment_model_id) AND (equipment_attrib_heading_deleted = 0) ORDER BY equipment_attrib_name">
<SelectParameters>
<asp:SessionParameter DefaultValue="" Name="equipment_model_id"
SessionField="EquipmentModelID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridViewAttribs" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="equipment_attrib_heading_id"
DataSourceID="SqlDataSourceAttribHeadings" ForeColor="#333333" GridLines="None"
style="margin-right: 0px">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="equipment_attrib_heading_id"
HeaderText="equipment_attrib_heading_id" ReadOnly="True"
SortExpression="equipment_attrib_heading_id" />
<asp:BoundField DataField="equipment_model_id" HeaderText="equipment_model_id"
SortExpression="equipment_model_id" />
<asp:BoundField DataField="equipment_attrib_name"
HeaderText="equipment_attrib_name" SortExpression="equipment_attrib_name" />
<asp:TemplateField HeaderText="equipment_attrib_value_details" SortExpression="equipment_attrib_value_details">
<ItemTemplate>
<asp:SqlDataSource ID="SqlDataSourceAttribValues" runat="server"
ConnectionString="<%$ ConnectionStrings:customer_support_devConnectionString %>"
ProviderName="<%$ ConnectionStrings:customer_support_devConnectionString.ProviderName %>"
SelectCommand="SELECT [equipment_attrib_value_details] FROM [equipment_new_attrib_values] WHERE (equipment_attrib_heading_id = #head_id) AND (equipment_id = #equipment_id) AND (equipment_attrib_value_deleted = 0)">
<SelectParameters>
<asp:QueryStringParameter Name="equipment_id" QueryStringField="id"
Type="Int32" />
<asp:ControlParameter ControlID="GridViewAttribs"
Name="head_id" PropertyName="SelectedDataKey.Values[equipment_attrib_heading_id]" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:ListView ID="ListViewAttribValues" runat="server"
DataSourceID="SqlDataSourceAttribValues">
<EmptyDataTemplate>
<table runat="server" style="">
<tr><td>No data was returned.</td></tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr style="">
<td><asp:Label ID="equipment_attrib_value_detailsLabel" runat="server" Text='<%# Eval("equipment_attrib_value_details") %>' /></td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table ID="itemPlaceholderContainer" runat="server" border="0" style="">
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The GridView displays all columns fine except the "equipment_attrib_value_details" column where I get "No data was returned."
However, if I take out the asp:ControlParameter which calls upon #head_id and use this hardcoded SELECT statement then I see the correct (albeit hardcoded) values:
SelectCommand="SELECT [equipment_attrib_value_details] FROM [equipment_new_attrib_values] WHERE (equipment_attrib_heading_id = 3) AND (equipment_id = #equipment_id) AND (equipment_attrib_value_deleted = 0)">
Therefore, for some reason, it would appear that the GridViewAttribs value of "equipment_attrib_heading_id" is not being passed to / picked up by the nested asp:ControlParameter
On the off chance, I've also tried replacing:
PropertyName="SelectedDataKey.Values[equipment_attrib_heading_id]"
With:
PropertyName="SelectedValue"
But this didn't resolve the issue either, still not data was returned.
If it helps, I'm using Visual Studio 2010 with ASP.NET4 (vb).
What you could try is using a hidden field and use that control for the controlparameter
<asp:TemplateField HeaderText="equipment_attrib_value_details" SortExpression="equipment_attrib_value_details">
<ItemTemplate>
<asp:HiddenField runat="server" ID="heading_id" Value='<%# Eval("equipment_attrib_heading_id") %>' />
<asp:SqlDataSource ID="SqlDataSourceAttribValues" runat="server"
ConnectionString="<%$ ConnectionStrings:customer_support_devConnectionString %>"
ProviderName="<%$ ConnectionStrings:customer_support_devConnectionString.ProviderName %>"
SelectCommand="SELECT [equipment_attrib_value_details] FROM [equipment_new_attrib_values] WHERE (equipment_attrib_heading_id = #head_id) AND (equipment_id = #equipment_id) AND (equipment_attrib_value_deleted = 0)">
<SelectParameters>
<asp:QueryStringParameter Name="equipment_id" QueryStringField="id" Type="Int32" />
<asp:ControlParameter ControlID="heading_id" Name="head_id" PropertyName="Value" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:ListView ID="ListViewAttribValues" runat="server"
DataSourceID="SqlDataSourceAttribValues">
<EmptyDataTemplate>
<table id="Table2" runat="server" style="">
<tr><td>No data was returned.</td></tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr style="">
<td><asp:Label ID="equipment_attrib_value_detailsLabel" runat="server" Text='<%# Eval("equipment_attrib_value_details") %>' /></td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table ID="itemPlaceholderContainer" runat="server" border="0" style="">
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
</ItemTemplate>
</asp:TemplateField>
This only works (it seems) if the HiddenField is inside the same ItemTemplate. If the DataSource is somewhere outside the TemplateField, in cases where you want to data-populate a control that is say on another column or field of the GridView, then the HiddenField will not work, as it's technically hidden.
The way to overcome this is in code-behind. Here is how I do it...
I have a TemplateField that is referring to #StudentID, which is actually a HiddenField in another TemplateField.
<asp:TemplateField HeaderText="Currently<br/>Tracking<br/>(past weeks)">
<ItemTemplate>
<asp:CheckBoxList ID="listWeeksTracking" runat="server" DataSourceID="sdsTETpastWeeks" DataTextField="WeekNo" DataValueField="WeekNo"
OnDataBound="listWeeksTracking_DataBound" OnDataBinding="listWeeksTracking_DataBinding"></asp:CheckBoxList>
<br />
<asp:SqlDataSource ID="sdsTETpastWeeks" runat="server" ConnectionString="<%$ ConnectionStrings:ATCNTV1ConnectionString %>"
SelectCommand="SELECT tb.WeekNo, ISNULL((SELECT TOP 1 ts.ETRTWtracking FROM tblTETMeetingStudent AS ts INNER JOIN tblTETMeeting AS tm ON tm.TETmeetingID = ts.TETmeetingID AND tm.WeekNo = tb.WeekNo WHERE ts.StudentID = #StudentID),0) AS Tracking FROM tblTETInstructionalTrainingBlocks AS tb WHERE tb.WeekNo <= #WeekNo AND tb.Active = 1 AND tb.YearNum = YEAR(#TETdate) ORDER BY tb.WeekNo">
<SelectParameters>
<asp:Parameter Name="StudentID" Type="string" />
<asp:ControlParameter ControlID="ddlWeekNo" Name="WeekNo" PropertyName="SelectedValue" Type="int16" />
<asp:ControlParameter ControlID="lblTETdate" Name="TETdate" Type="DateTime" />
</SelectParameters>
</asp:SqlDataSource>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Wrap="False" />
</asp:TemplateField>
So I define the #StudentID parameter as simple a parameter, and not a ControlParameter, is it won't be able to pick up the hiddenfield elsewhere in my GridView.
In code-behind (C#), I trap the Selecting event via the DataBinding.
And in there I specifically look for the row in relation to the control I've just populated (or about to), and then I look for the HiddenField.
protected void listWeeksTracking_DataBinding(object sender, EventArgs e)
{
//set the parameter for the StudentID here as using hiddenfields does not work directly in asp.net, as they are hidden!
CheckBoxList cbl1 = (CheckBoxList)sender;
GridViewRow gvRow = (GridViewRow)cbl1.NamingContainer;
if (gvRow != null)
{
SqlDataSource sdsTETpastWeeks = (SqlDataSource)gvRow.FindControl("sdsTETpastWeeks");
HiddenField hfStudentID = (HiddenField)gvRow.FindControl("hfStudentID");
if (hfStudentID != null) sdsTETpastWeeks.SelectParameters["StudentID"].DefaultValue = hfStudentID.Value.ToString();
}
}
Voila!

Resources