TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ali johari
NA
1
2.8k
cannot access to the FileUpload control at code behind
Mar 21 2015 5:44 PM
Hi,
I use the asp:FileUpload in asp:GridView.FooterRow
and cannot access to the FileUpload control at code behind
please help me
tnx
design view:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:label ID="lblMessage" runat="server" Text=""></asp:label>
<asp:GridView ID="gv" runat="server" CssClass="gv" AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="EDS" ShowFooter="True" OnRowCommand="gv_RowCommand">
<Columns>
<asp:TemplateField HeaderText="ID" SortExpression="id">
<EditItemTemplate>
<asp:Label ID="lblId" runat="server" Text='<%# Eval("id") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblId" runat="server" Text='<%# Bind("id") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:ImageButton ID="ibInsert" runat="server" CausesValidation="true" CommandName="Insert" ImageUrl="~/App_Themes/Default/images/Insert-alt.png" Text="Insert" ToolTip="Insert" />
</FooterTemplate>
<ItemStyle Width="5%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="TITLE" SortExpression="title">
<EditItemTemplate>
<asp:TextBox ID="txtTitle" runat="server" Text='<%# Bind("title") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblTitle" runat="server" Text='<%# Bind("title") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtTitle" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemStyle Width="25%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="CONTENT" SortExpression="content">
<EditItemTemplate>
<asp:TextBox ID="txtContent" runat="server" Text='<%# Bind("content") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblContent" runat="server" Text='<%# Bind("content") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtContent" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemStyle Width="55%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="IMAGE" SortExpression="image">
<EditItemTemplate>
<asp:Image ID="imgImage" runat="server" ImageUrl='<%# Bind("image") %>' />
<asp:FileUpload ID="fuImage" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:Image ID="imgImage" runat="server" ImageUrl='<%# Bind("image") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:FileUpload ID="fuImage" runat="server" />
</FooterTemplate>
<ItemStyle Width="10%" />
</asp:TemplateField>
<asp:TemplateField ShowHeader="False" ItemStyle-Width="5%">
<ItemTemplate>
<asp:ImageButton ID="ibEdit" runat="server" CausesValidation="False" CommandName="Edit" ImageUrl="~/App_Themes/Default/images/edit.png" Text="Edit" ToolTip="Edit" />
<asp:ImageButton ID="ibDelete" runat="server" CausesValidation="False" CommandName="Delete" ImageUrl="~/App_Themes/Default/images/delete.png" Text="Delete" ToolTip="Delete" />
</ItemTemplate>
<EditItemTemplate>
<asp:ImageButton ID="ibUpdate" runat="server" CausesValidation="True" CommandName="Update" ImageUrl="~/App_Themes/Default/images/update.png" Text="Update" ToolTip="Update" />
<asp:ImageButton ID="ibCancel" runat="server" CausesValidation="False" CommandName="Cancel" ImageUrl="~/App_Themes/Default/images/cancel.png" Text="Cancel" ToolTip="Cancel" />
</EditItemTemplate>
<ItemStyle Width="5%"></ItemStyle>
</asp:TemplateField>
</Columns>
<PagerSettings Mode="NextPrevious" />
</asp:GridView>
<asp:EntityDataSource ID="EDS" runat="server" ConnectionString="name=ShirdalDBEntities" DefaultContainerName="ShirdalDBEntities" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="Descriptions" EntityTypeFilter="Description">
</asp:EntityDataSource>
</ContentTemplate>
</asp:UpdatePanel>
design view:
-----------------------------------------------------------------------------------------------
code view:
protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
{
String path = Server.MapPath("~/Upload/Images/");
if (e.CommandName == "Insert")
{
description = new Description();
GridViewRow row = gv.FooterRow;
TextBox txtTitle = row.FindControl("txtTitle") as TextBox;
TextBox txtContent = row.FindControl("txtContent") as TextBox;
FileUpload fuImage = row.FindControl("fuImage") as FileUpload;
try
{
using (context = new DBEntities())
{
description.title = txtTitle.Text;
description.content = txtContent.Text;
description.image = path + fuImage.FileName;
if (File.Exists(Server.MapPath(path + fuImage.FileName)))
{
lblMessage.Text = " ";
}
else
{
((FileUpload)row.FindControl("fuImage")).SaveAs(Server.MapPath(path + fuImage.FileName));
lblMessage.Text = " ";
}
context.Descriptions.Add(description);
context.SaveChanges();
}
}
catch (Exception)
{
throw;
}
Response.Redirect("");
}
}
code view:
Reply
Answers (
3
)
combine the same id in mysql so one colomn
change password in mvc without membership