For this example i'm using Nivo Slider for practice. You can be creative and use any type of slide.

Create The Database

In order to do the dynamic slide, first of all you should make the database in MSSQL server in this format.
database dynamic slideshow aspnet Creating Dynamic Slideshow in ASP.net 4.0
Why there is a status column?
I making this is because i want to make sure we can turn it on and off in the backend of our website, for example discount for Christmas slide we only need to make it on and of at certain time.
At this point, i'm assuming that your database is already connected into your web application.
The next step is go to the page where you want to put your slide show is. For example your home page.

Call the script

Call the code in head of your page. This example i'm using my own master page.
  1. <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
  2. <link rel="stylesheet" href="slider/default/default.css" type="text/css" media="screen" />
  3. <link rel="stylesheet" href="slider/nivo-slider.css" type="text/css" media="screen" />
  4. <script type="text/javascript" src="slider/jquery-1.6.1.min.js"></script>
  5. <script type="text/javascript" src="slider/jquery.nivo.slider.pack.js"></script>
  6. <script type="text/javascript">
  7. $(window).load(function () {
  8. $('#slider').nivoSlider();
  9. });
  10. </script>
  11. </asp:Content>
Do mention do not copy paste, examine the header ID, allocate the script right to make it work.

Call the HTML into your application using Repeater Control

Use the Repeater Control to call the slide show
Why is repeater control? Is because repeater control only call the plain format without extra span tag in between.
Here is the step in design view
First of all drag a repeater control into design view
repeater control Creating Dynamic Slideshow in ASP.net 4.0
and next step is to call the database
specify column database Creating Dynamic Slideshow in ASP.net 4.0
and do not forget to choose the where button.
This is making sure the data that shown only the status column = true
This is just a fancy stuff. you can skip it if you want.
where status is true Creating Dynamic Slideshow in ASP.net 4.0
Once you finished, the repeater control is not call the template by it self.
You should type in the code your self. Go to the middle of repeater control and type in the code like this.
  1. <asp:Repeater ID="Repeater1" runat="server" DataSourceID="Slideshow">
  2. <ItemTemplate>
  3. <asp:Image Width="940" Height="400" ID="Image1" ImageUrl='<%# Eval("Image") %>' runat="server" />
  4. </ItemTemplate>
  5. </asp:Repeater>
Explanation : This is just calling the image one by one and the javascript will do the rest

As you finished, you will have the finished code like this.
  1. <div class="slider-wrapper theme-default">
  2. <div class="ribbon"></div>
  3. <div id="slider" class="nivoSlider">
  4. <asp:Repeater ID="Repeater1" runat="server" DataSourceID="Slideshow">
  5. <ItemTemplate>
  6. <asp:Image Width="940" Height="400" ID="Image1" ImageUrl='<%# Eval("Image") %>' runat="server" />
  7. </ItemTemplate>
  8. </asp:Repeater>
  9.  
  10. <asp:SqlDataSource ID="Slideshow" runat="server"
  11. ConnectionString="<%$ ConnectionStrings:THE_NAME_OF_YOUR_CONNECTION_STRING%>"
  12. SelectCommand="SELECT [slideID], [Image] FROM [slideshow] WHERE ([status] = @status)">
  13. <SelectParameters>
  14. <asp:Parameter DefaultValue="True" Name="Status" Type="Boolean" />
  15. </SelectParameters>
  16. </asp:SqlDataSource>
  17. </div>
  18. </div>
Now this is just half the way. what we need to do is make the back end so we can change the slide show, upload, activating and deactivated the slide.

Create the grid View For edit, enabling and deactivated the slide

In your admin area, create a page call slide.aspx
Create a gridView Control
  1. <asp:GridView ID="GridView1" runat="server" GridLines="None" CssClass="stdtbl"
  2. Width="500px" AutoGenerateColumns="False"
  3. DataKeyNames="slideID" DataSourceID="slide">
  4. <Columns>
  5. <asp:BoundField Visible="false" DataField="slideID" HeaderText="slideID" InsertVisible="False"
  6. ReadOnly="True" SortExpression="slideID" />
  7. <asp:BoundField DataField="Image" Visible="false" HeaderText="Image" SortExpression="Image" />
  8. <asp:TemplateField>
  9. <ItemTemplate>
  10. <asp:Image ID="Image1" ImageUrl='<%# Eval("Image", "~/{0}") %>' Width="200" runat="server" />
  11. </ItemTemplate>
  12. <EditItemTemplate>
  13. <asp:TextBox ID="TextBox1" ReadOnly="true" Enabled="false" Text='<%# Bind("Image") %>' runat="server"></asp:TextBox>
  14. </EditItemTemplate>
  15. </asp:TemplateField>
  16. <asp:CheckBoxField DataField="status" HeaderText="status"
  17. SortExpression="status" />
  18. <asp:CommandField ButtonType="Button" ShowDeleteButton="True"
  19. ShowEditButton="True" />
  20. </Columns>
  21. </asp:GridView>
  22.  
  23. <asp:SqlDataSource ID="slide" runat="server"
  24. ConnectionString="<%$ ConnectionStrings:YOUR_CONNECTION_STRING_NAME %>"
  25. DeleteCommand="DELETE FROM [slideshow] WHERE [slideID] = @slideID"
  26. InsertCommand="INSERT INTO [slideshow] ([Image], [status]) VALUES (@Image, @status)"
  27. SelectCommand="SELECT * FROM [slideshow]"
  28. UpdateCommand="UPDATE [slideshow] SET [Image] = @Image, [status] = @status WHERE [slideID] = @slideID">
  29. <DeleteParameters>
  30. <asp:Parameter Name="slideID" Type="Int32" />
  31. </DeleteParameters>
  32. <InsertParameters>
  33. <asp:Parameter Name="Image" Type="String" />
  34. <asp:Parameter Name="status" Type="Boolean" />
  35. </InsertParameters>
  36. <UpdateParameters>
  37. <asp:Parameter Name="Image" Type="String" />
  38. <asp:Parameter Name="status" Type="Boolean" />
  39. <asp:Parameter Name="slideID" Type="Int32" />
  40. </UpdateParameters>
  41. </asp:SqlDataSource>
Do mention that you need to generate Update, Delete in here in order to enabling and disabling the slide.
Change the CONNECTION STRING name into your's, and now we got the list of your slideshow.
now you should have a page look like this
backend slideshow1 Creating Dynamic Slideshow in ASP.net 4.0

Adding a Slideshow

Now you probably asking, how to add the slide since we don't have any......
Now add a button in the top or bottom of the page by dragin a button control.
  1. <asp:Button ID="newslide" PostBackUrl="~/admin/newslide.aspx" runat="server" Text="Add New slide" />
and create a new page in your admin area call this baby newslide.aspx
For this page we going to use the formView Control.
  1. <asp:FormView ID="FormView1" runat="server" DataKeyNames="slideID"
  2. DataSourceID="newslide" DefaultMode="Insert"
  3. oniteminserting="FormView1_ItemInserting">
  4. <EditItemTemplate>
  5.  
  6. </EditItemTemplate>
  7. <InsertItemTemplate>
  8. <h2 class="featured">Add New Slideshow Image</h2>
  9. <table class="admintable">
  10. <tr><th>
  11. Image:</th><td>
  12. <asp:FileUpload ID="uploadslide" runat="server" />
  13. <asp:TextBox Visible="false" ID="ImageTextBox" runat="server" Text='<%# Bind("Image") %>' />
  14. </td></tr>
  15.  
  16. <tr><th>
  17. status:</th><td>
  18. <asp:CheckBox ID="statusCheckBox" runat="server"
  19. Checked='<%# Bind("status") %>' />
  20. </td></tr>
  21.  
  22. </table>
  23. <asp:Button ID="InsertButton" runat="server" CausesValidation="True"
  24. CommandName="Insert" Text="Insert" />
  25. &nbsp;<asp:Button ID="InsertCancelButton" runat="server"
  26. CausesValidation="False" CommandName="Cancel" Text="Cancel" /><br />
  27.  
  28. <em class="small red">Image size is 940px width and 400px height</em>
  29. </InsertItemTemplate>
  30. <ItemTemplate>
  31. slideID:
  32. <asp:Label ID="slideIDLabel" runat="server" Text='<%# Eval("slideID") %>' />
  33. <br />
  34. Image:
  35. <asp:Label ID="ImageLabel" runat="server" Text='<%# Bind("Image") %>' />
  36. <br />
  37. status:
  38. <asp:CheckBox ID="statusCheckBox" runat="server"
  39. Checked='<%# Bind("status") %>' Enabled="false" />
  40. <br />
  41. <asp:Button ID="EditButton" runat="server" CausesValidation="False"
  42. CommandName="Edit" Text="Edit" />
  43. &nbsp;<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False"
  44. CommandName="Delete" Text="Delete" />
  45. &nbsp;<asp:Button ID="NewButton" runat="server" CausesValidation="False"
  46. CommandName="New" Text="New" />
  47. </ItemTemplate>
  48. </asp:FormView>
  49. <asp:SqlDataSource ID="newslide" runat="server"
  50. ConnectionString="<%$ ConnectionStrings:YOUR_CONNECTION_STRING_NAME %>"
  51. DeleteCommand="DELETE FROM [slideshow] WHERE [slideID] = @slideID"
  52. InsertCommand="INSERT INTO [slideshow] ([Image], [status]) VALUES (@Image, @status)"
  53. SelectCommand="SELECT * FROM [slideshow]"
  54. UpdateCommand="UPDATE [slideshow] SET [Image] = @Image, [status] = @status WHERE [slideID] = @slideID">
  55. <DeleteParameters>
  56. <asp:Parameter Name="slideID" Type="Int32" />
  57. </DeleteParameters>
  58. <InsertParameters>
  59. <asp:Parameter Name="Image" Type="String" />
  60. <asp:Parameter Name="status" Type="Boolean" />
  61. </InsertParameters>
  62. <UpdateParameters>
  63. <asp:Parameter Name="Image" Type="String" />
  64. <asp:Parameter Name="status" Type="Boolean" />
  65. <asp:Parameter Name="slideID" Type="Int32" />
  66. </UpdateParameters>
  67. </asp:SqlDataSource>
Ow yeah, it's complete with the validation... do use it to ensure no crap is added to the database....

Now go to the back of the page ( newslide.aspx.cs ) and add the code
  1. protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
  2. {
  3. FileUpload slideupload = (FileUpload)FormView1.Row.FindControl("uploadslide");
  4.  
  5. if (slideupload.HasFile)
  6. {
  7. slideupload.SaveAs(Server.MapPath("..//" + "images" + "//" + "slideshow") + "//" + slideupload.FileName);
  8. e.Values["Image"] = "images/slideshow/" + slideupload.FileName;
  9. }
  10. // explanation : mapPath is the location of where the uploaded file where to be stored.
  11. // e.values[your_database_column] = "value you want to insert into your database"
  12. }
This code, you have to change the structure depend on structure of your site.
you should have a page look like this
backend slideshow2 Creating Dynamic Slideshow in ASP.net 4.0
and Walaaaa.... it's done.