本文介绍了无法在Datagrid中使用Fileuploader更新图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用datagrid来显示一些带有图片的记录.它完美地工作.当我要修改特定的单元格时,除图片外,所有数据均被修改.我在datagrid内部使用fileuploader.任何人都请帮助解决此问题.
这是我的代码:

i am using datagrid to display some records with picture. It works perfectly. When i am going to modify a particular cell every data are modified except the picture. i am using fileuploader inside the datagrid. anyone please help to to solve this.
Here is my code:

protected void dgsectortariff_update(object source, DataGridCommandEventArgs e)
    {
        try
        {
            TextBox type = (TextBox)(e.Item.Cells[1].Controls[0]);
            TextBox reg = (TextBox)(e.Item.Cells[2].Controls[0]);
            TextBox owner = (TextBox)(e.Item.Cells[3].Controls[0]);
            TextBox mob1 = (TextBox)(e.Item.Cells[4].Controls[0]);
            TextBox mob2 = (TextBox)(e.Item.Cells[5].Controls[0]);
            TextBox vname = (TextBox)(e.Item.Cells[6].Controls[0]);
            TextBox dname = (TextBox)(e.Item.Cells[7].Controls[0]);
            TextBox dmob = (TextBox)(e.Item.Cells[8].Controls[0]);
            FileUpload Image = (FileUpload)(e.Item.Cells[9].Controls[1]);
            if (reg.Text == "")
            {
                cls.MsgBox("Registration Cannot be Empty", this.Page);
                return;
            }
            if (Image.FileName != "")
            {
                if (File.Exists(Server.MapPath("VehiclePic/" + dgsectortariff.DataKeys[e.Item.ItemIndex] + ".jpg")))
                    File.Delete(Server.MapPath("VehiclePic/" + dgsectortariff.DataKeys[e.Item.ItemIndex] + ".jpg"));
                Image.SaveAs(Server.MapPath("VehiclePic/" + dgsectortariff.DataKeys[e.Item.ItemIndex] + ".jpg"));
            }





Image

尽管我选择了一张图片,但每次都有HasFile属性显示为false.

我认为fileuploader无法正常工作.

这是我的aspx文件

HasFile property is showing false every time though i have selected a picture.

I think the fileuploader is not working.

Here is my aspx file

<asp:DataGrid ID="dgsectortariff" runat="server" AutoGenerateColumns="false" CssClass="GridViewStyle"
                    Height="315px" Width="781px" oncancelcommand="dgsectortariff_cancel" ondeletecommand="dgsectortariff_delete" 
                    oneditcommand="dgsectortariff_edit" onpageindexchanged="dgsectortariff_PageIndexChanged" 
                    onupdatecommand="dgsectortariff_update"
                    AllowPaging="true" AllowSorting="true" DataKeyField="id" PageSize="6"
                    BackColor="#2E2E2E" >
                    <PagerStyle HorizontalAlign="Center" Mode="NumericPages" CssClass="grid_paging" 
                         Position="TopAndBottom"/>
                    <columns>
                <asp:BoundColumn DataField="id" HeaderText="Vehicle ID" Visible="false" />
                <asp:BoundColumn DataField="v_type" HeaderText="Vehicle Type" />
                             <asp:BoundColumn DataField="v_name" HeaderText="Vehicle" />
                             <asp:TemplateColumn HeaderText="Image">
                                <ItemTemplate>
                                    <ul>
                                        <li>
                                            <a href="#"><img id="imgSmall" src=''VehiclePic/<%# DataBinder.Eval(Container,"DataItem.v_image") %>'' alt="Gallery Image" width="100" height="100" /></a>
                                        </li>
                                    </ul>                                            
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:FileUpload ID="flUploadGrid" runat="server" ForeColor="#2A2F0F"></asp:FileUpload>
                                </EditItemTemplate>
                                <HeaderStyle Width="110px" />
                                </asp:TemplateColumn>
                <asp:EditCommandColumn CancelText="Cancel" HeaderText="Modify" UpdateText="Update"/>                                     
                     <ASP:TemplateColumn HeaderText="Action"> 
                    <ItemTemplate> 
                    <ASP:ImageButton id="btnEdit"  runat="server" AlternateText="Edit" 
                        ImageUrl="~/Admin/images/edit.png" CommandArgument=''<%# 
                        DataBinder.Eval(Container,"DataItem.id")%>'' CommandName="Edit"/> 
                    <ASP:ImageButton id="btnDel"  runat="server" AlternateText="Delete" 
                        ImageUrl="~/Admin/images/delete.png" CommandArgument=''<%# 
                        DataBinder.Eval(Container,"DataItem.id")%>'' CommandName="Delete"  önClientClick="return confirm(''Are you sure you want to delete this ?'');"/> 
                    </ItemTemplate> 
                    </ASP:TemplateColumn>                                                     
                                            
                </columns>
                    </asp:DataGrid>

推荐答案


这篇关于无法在Datagrid中使用Fileuploader更新图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 22:35