I have a problem that has been a thorn in my side for nearly a week. I have a site that users can create an account and load videos of there choosing from a database. I would like the videos to show up in a certain order on there page when they look at the ones they selected. My problem is that the videos show up in a random order. I know this may be basic but I am just now entry level (has only been two weeks since I graduated). All the functionality works, so no help needed there, just this darn order thing.
Specs:
Coded in C# ASP.NET
They add and delete selections via checkbox list.
I have the items databound so I can add and remove videos on the back end.
I know this may get me some minus votes, and though I would prefer it not, I just need some help with this issue to be done with the whole project. Before you yell at me for not having code, please tell me what you would like to see so I don’t add tons of useless code.
I am not trying to me short, rather I am frustrated that everything I tried won’t work.
Thank you in advance.
EDIT:
Here is the SqlDataSource for it:
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:fivideoConnectionString %>"
ProviderName="<%$ ConnectionStrings:fivideoConnectionString.ProviderName %>"
InsertCommand="INSERT INTO dealervideo(DealerRecID,VideoRecID) VALUES (?,?)"
DeleteCommand="DELETE FROM dealervideo where RecID = ?" >
<DeleteParameters>
<asp:SessionParameter Name="recid" SessionField="videorecid" />
</DeleteParameters>
<InsertParameters>
<asp:ControlParameter ControlID="hidRecID" Name="recid" PropertyName="Value" />
<asp:SessionParameter Name="videorecid" SessionField="videorecid" />
</InsertParameters>
</asp:SqlDataSource>
And here is the Gridview:
<asp:GridView ID="GridView2" runat="server"
DataSourceID="SqlDataSource2" AutoGenerateColumns="False"
DataKeyNames="RecID" CellSpacing="5" BorderStyle="None" BorderWidth="0px">
<Columns>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:CheckBox ID="cbDelete" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
</Columns>
</asp:GridView>
And this is the event when they click to add a video to the list:
protected void btnAddVideo_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvr in GridView3.Rows)
{
CheckBox chkItem = (CheckBox)gvr.FindControl("cbAdd");
if (chkItem.Checked)
{
String sRecID = GridView3.DataKeys[gvr.RowIndex].Value.ToString();
Session["videorecid"] = sRecID;
SqlDataSource2.Insert();
SqlDataSource2.SelectCommand = "SELECT * FROM dealervideo inner join videos on videos.RecID = dealervideo.VideoRecID inner join dealers on dealers.RecID = dealervideo.DealerRecID where dealers.RecID = " + hidRecID.Value;
}
}
GridView2.DataBind();
Add an “ORDER BY” to your Select Command and the field which you want it to be ordered on.
Example: