Name : Uday Shah - HOD (IT)
Contact No : 7600044051
E-Mail : rupareleducation@gmail.com
-----------------------------------------------------------------
Dynamic Image Upload in Database and Display it using Literal Control in Asp.net with C#
Admin Side
Video.aspx
<table style="width: 100%">
<tr style="width: 100%">
<td style="width: 100%" align="center"
colspan="2"
valign="top">
<h2>
:: Videos ::
</h2>
</td>
</tr>
<tr style="width: 100%">
<td style="width: 50%; text-align: right">
Name:
</td>
<td style="width: 50%" align="left">
<asp:TextBox ID="TextBox3"
runat="server"></asp:TextBox>
</td>
</tr>
<tr style="width: 100%">
<td style="width: 50%; text-align: right">
Video:
</td>
<td style="width: 50%" align="left">
<asp:FileUpload ID="FileUpload1"
runat="server"
/>
</td>
</tr>
<tr style="width: 100%">
<td style="width: 50%" align="right">
<asp:Button ID="Button1"
runat="server"
Text="Submit"
onclick="Button1_Click"
/>
</td>
<td style="width: 50%" align="left">
<asp:Button ID="Button2"
runat="server"
Text="Cancel"
/>
</td>
</tr>
</table>
-------------------------------------------------------------------------------
Video.aspx.cs
Add this Name Space
using System.Web.Configuration;
using System.Data.SqlClient;
Button Click Event
string s = WebConfigurationManager.ConnectionStrings["cs"].ToString();
SqlConnection cn = new
SqlConnection(s);
string path = Server.MapPath("~/img/"
+ FileUpload1.FileName);
FileUpload1.SaveAs(path);
string pic = FileUpload1.FileName.ToString();
cn.Open();
SqlCommand cmd
= new SqlCommand("insert into video values('" +
TextBox3.Text + "','" + pic + "')", cn);
cmd.ExecuteNonQuery();
Visitor Side
Videodisp.aspx
<table style="width: 100%">
<tr style="width: 100%">
<td style="width: 100%" align="center">
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="name" DataValueField="video" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:ConnectionString %>" SelectCommand="SELECT *
FROM [Video]">
</asp:SqlDataSource>
<asp:Button ID="Button3"
runat="server"
OnClick="Button3_Click"
Text="Button"
/>
</td>
</tr>
<tr style="width: 100%">
<td style="width: 100%" align="center">
<div class="borded">
<asp:Literal ID="Literal1" runat="server" Text=""></asp:Literal>
</div>
</td>
</tr>
</table>
Admin View
Visitor View