本文介绍了gridview中editItemTemplate中的fileupload控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我创建了一个页面,其中在网格视图中显示了图像名称(ImageName)和图像(Image).

现在,当点击编辑编辑"按钮时,我应该得到一个文本框来更新ImageName和一个文件上传控件来将一个新的Image更新到数据库中.

ImageEdit.aspx-代码

hello all.

I have made a page where image name (ImageName) and image (Image) gets displayed in a gridview.

now when hitting the edit ''Edit'' button i should get a textbox to update the ImageName and a fileupload control to update a new Image into database.

ImageEdit.aspx - code

<asp:GridView ID="gvImages" runat="server" AutoGenerateColumns="False"

            DataKeyNames="ImageID" DataSourceID="SqlDataSource1"

            onselectedindexchanged="gvImages_SelectedIndexChanged" Width="500px"

            onrowcommand="gvImages_RowCommand" onrowediting="gvImages_RowEditing"

            onrowupdated="gvImages_RowUpdated">
            <Columns>
                <asp:BoundField DataField="ImageName" HeaderText="ImageName"

                    SortExpression="ImageName" />
                      <asp:TemplateField HeaderText="Image">
                          <EditItemTemplate>
                              <asp:FileUpload ID="fuImage" runat="server" />
                              &nbsp;<asp:Button ID="Button1" runat="server" onclick="Button1_Click"

                                  Text="Upload" />
                          </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Image ID="Image1" runat="server"

                            ImageUrl='<%# "ImageHandler.ashx?ImID="+ Eval("ImageID")  %>' />
                    </ItemTemplate>
                    <ControlStyle Height="100px" Width="100px" />
                </asp:TemplateField>
                <asp:CommandField ShowEditButton="True" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"

            ConnectionString="<%$ ConnectionStrings:EmployeeConnectionString %>"

            DeleteCommand="DELETE FROM [ImageTab] WHERE [ImageID] = @ImageID"

            InsertCommand="INSERT INTO [ImageTab] ([ImageName]) VALUES (@ImageName)"

            SelectCommand="SELECT [ImageName], [ImageID] FROM [ImageTab]"

            UpdateCommand="UPDATE [ImageTab] SET [ImageName] = @ImageName WHERE [ImageID] = @ImageID">
            <DeleteParameters>
                <asp:Parameter Name="ImageID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="ImageName" Type="String" />
                <asp:Parameter Name="ImageID" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="ImageName" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>





ImageEdit.aspx.cs-背后的代码





ImageEdit.aspx.cs - code behind

protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString);
        SqlCommand command = new SqlCommand("SELECT imagename,ImageID from [ImageTab]", connection);
        SqlDataAdapter ada = new SqlDataAdapter(command);
        ada.Fill(dt);
        //gvImages.DataSource = dt;
        gvImages.DataBind();


    }




我还提供了ImageHandler.ashx用于显示图像.

我想知道我该怎么做.因此,当我按下更新"按钮时,应更新新名称,并上载新图像代替旧图像.




I have also provided a ImageHandler.ashx for displaying the images.

i want to know how can i implement this thing. So that when i hit the Update button, the new name should be updated and the new image gets uploaded in place of old image.

推荐答案





ImageEdit.aspx.cs-背后的代码





ImageEdit.aspx.cs - code behind

protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString);
        SqlCommand command = new SqlCommand("SELECT imagename,ImageID from [ImageTab]", connection);
        SqlDataAdapter ada = new SqlDataAdapter(command);
        ada.Fill(dt);
        //gvImages.DataSource = dt;
        gvImages.DataBind();


    }




我还提供了ImageHandler.ashx用于显示图像.

我想知道我该怎么做.这样,当我按下更新"按钮时,应更新新名称,并上载新图像代替旧图像.




I have also provided a ImageHandler.ashx for displaying the images.

i want to know how can i implement this thing. So that when i hit the Update button, the new name should be updated and the new image gets uploaded in place of old image.


这篇关于gridview中editItemTemplate中的fileupload控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 21:57