C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » ASP.NET WebForms »

File upload control


Posted Date: 30 Jun 2009    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: ElzMember Level: Gold    
Rating: 1 out of 5Points: 7 (Rs 5)



Hi ,
If u want to upload multiple files this code will help.By selecting dropdown value corresponding file upload controls will get generated.No need to palce all fileuploads on the form.


<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" Height="153px"
Width="300px">
<Columns>
<asp:BoundField DataField="serial" HeaderText="No" />
<asp:TemplateField HeaderText="Upload Items">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text="Path"></asp:Label>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Label ID="Label2" runat="server" Text="Description"></asp:Label>
<asp:TextBox ID="txtdes" runat="server"></asp:TextBox><br>

<asp:RadioButton ID="chkk1" Text="Lock" runat="server" GroupName="j" />
<asp:Image ID="Image2" runat="server" ImageUrl="~/images/locked.gif" />

<asp:RadioButton ID="chkk2" Text="UnLock" runat="server" Checked="true" GroupName="j" />
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/unlocked.gif" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

<asp:DropDownList ID="drpupload" runat="server" CssClass="select"
AutoPostBack="True"
onselectedindexchanged="drpupload_SelectedIndexChanged1" Visible="False" >

<asp:ListItem Value="0" Selected="True">Multiple File Upload</asp:ListItem>
<asp:ListItem Value="1">Upload 2 files</asp:ListItem>
<asp:ListItem Value="2">Upload 3 files</asp:ListItem>
<asp:ListItem Value="3">Upload 4 files</asp:ListItem>
<asp:ListItem Value="4">Upload 5 files</asp:ListItem>
<asp:ListItem Value="5">Upload 6 files</asp:ListItem>
<asp:ListItem Value="6">Upload 7 files</asp:ListItem>
<asp:ListItem Value="7">Upload 8 files</asp:ListItem>
<asp:ListItem Value="8">Upload 9 files</asp:ListItem>
<asp:ListItem Value="9">Upload 10 files</asp:ListItem>
<asp:ListItem Value="10">Upload 11 files</asp:ListItem>
<asp:ListItem Value="11">Upload 12 files</asp:ListItem>
<asp:ListItem Value="12">Upload 13 files</asp:ListItem>
<asp:ListItem Value="13">Upload 14 files</asp:ListItem>
<asp:ListItem Value="14">Upload 15 files</asp:ListItem>
</asp:DropDownList>



protected void drpupload_SelectedIndexChanged1(object sender, EventArgs e)
{

if (drpupload.SelectedItem.Text == "Multiple File Upload")
{
GridView2.Visible = false;

}

else
{
Panel1.Visible = false;
GridView2.Visible = true;
dt.Columns.Add("serial");
int n;
n = Convert.ToInt32(drpupload.SelectedItem.Value);
for (int i = 0; i <= n; i++)
{
dt.Rows.Add();
dt.Rows[i]["serial"] = i + 1;

}
GridView2.DataSource = dt;
GridView2.DataBind();
}
}



Responses

Author: Miss Meetu Choudhary    30 Jun 2009Member Level: Diamond   Points : 1
please format your resources properly. use the
 
block and proper HTML keywords and tags. to format

++
Thanks and Regards
Miss Meetu Choudhary
Sr. Editor



Author: Elz    30 Jun 2009Member Level: Gold   Points : 0
Hi
How to do that Meetu?


Author: Miss Meetu Choudhary    30 Jun 2009Member Level: Diamond   Points : 1
use [cod][/cod] block to for indicating the code block block and remember you have to use code instead of cod i omitted the e to display the tag. and use &.l.t.; for < and &.g.t.; for > without . i have used that to display the keyword.

++
Thanks and Regards
Meetu Choudhary
Sr. Editor


Author: Elz    30 Jun 2009Member Level: Gold   Points : 0
Thanks


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
File upload  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Reading / Writing data from Excel in ASP.Net
Previous Resource: Checks number or not
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use