Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 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>
Posted
Updated 2-May-12 3:07am
v2
Comments
Sandeep Mewara 1-May-12 2:44am    
Did you used DEBUGGER? What is happening? Execution is as per expected? Where it fails?

1 solution

Hi,
Please follow the link[^].

This may help you.

-AK
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900