本文介绍了是否可以在asp.net的gridview列中放置一个上传图像按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我有其中具有更新和删除功能的网格视图.现在的问题是所有列都正确更新.

但是要更新图像,我想要一个上传控件.

所以我想知道如何在网格视图中放置图像的上传控件.

我有模板.

我试图放置一个上传控件.
但是对于C#代码,如何双击它.

我的代码如下:

Hello

I have grid view in which update and delete functionality is there. Now the problem is all the columns are updating properly.

But for updating an image i want to have a upload contol.

So i want to know how to place an upload control for the image in grid view.

I have templates.

I tried to put an upload control.
But for c# code how to double click it.

My Code is as follows:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MainTable.aspx.cs" Inherits="commonlogin.MainTable" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>GridView</title>

    <link href="Content/StyleSheet1.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>

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

            AutoGenerateDeleteButton="True" onrowdeleted="GridView1_RowDeleted" AutoGenerateEditButton ="True"

            onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"

            onrowupdating="GridView1_RowUpdating"

            onpageindexchanging="GridView1_PageIndexChanging"

            onrowcancelingedit="GridView1_RowCancelingEdit" AllowPaging="True" CssClass ="bodytext"

            AllowSorting="True" BackColor="White" BorderColor="#336666"

            BorderStyle="Double" BorderWidth="3px" CellPadding="4"

            GridLines="Horizontal" onselectedindexchanged="GridView1_SelectedIndexChanged" >


        <Columns>


            <asp:TemplateField HeaderText="ID"  >
                <%--<EditItemTemplate>
                    <asp:TextBox ID="txtID" runat="server" Text='<%# Bind("ID") %>'></asp:TextBox>
                </EditItemTemplate>--%>
                <ItemTemplate>
                 <%--<asp:Label ID="Label1" runat="server" ImageUrl='<%# "Handler1.ashx?ID=" + Eval("ID")%>'  Text='<%# Bind("ID") %>'></asp:Label>--%>
                    <asp:Label ID="lblID" runat="server" CssClass="bodytext"   Text='<%# Bind("ID") %>'></asp:Label>
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Left" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Name">
                <EditItemTemplate>
                    <asp:TextBox ID="txtName" runat="server" CssClass ="TextBox"  Text='<%# Bind("Name") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblName" runat="server" CssClass="bodytext"  Text='<%# Bind("Name") %>'></asp:Label>
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Left" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Description">
                <EditItemTemplate>
                    <asp:TextBox ID="txtDesc" runat="server" CssClass ="TextBox"  Text='<%# Bind("Description") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblDesc" runat="server" CssClass="bodytext"  Text='<%# Bind("Description") %>'></asp:Label>
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Left" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Image">
                <EditItemTemplate>
                    <asp:TextBox ID="txtImage" runat="server" CssClass ="TextBox"   Text='<%# Bind("Image") %>' ></asp:TextBox>
                    <asp:FileUpload ID="FileUpload2" runat="server" />
                <asp:Button ID="btnUpdate" runat="server" OnClick="btnUpdate_Click" Text="Update Image" />
                <%--<asp:TextBox ID="txtImage" runat="server" CssClass ="TextBox"></asp:TextBox>--%>

                </EditItemTemplate>
                <ItemTemplate>
                <asp:Image ID="Image1" runat="server"  ImageUrl='<%# "Handler1.ashx?ID=" + Eval("ID")%>'/>






                <%--<asp:Image ID="Image2" runat="server" ImageUrl='<%# "Handler1.ashx?ID=" + Bind("ID")%>'/>--%>

                    <%--<asp:Label ID="lblImage" runat="server"  Text='<%# Bind("Image") %>'></asp:Label>--%>

                    <%--<asp:Label ID="lblImage" runat="server"  ImageUrl='<%# "Handler1.ashx?ID=" + Eval("ID") %>'></asp:Label>--%>
                    <%--<asp:Label ID="Label1" runat="server" ImageUrl='<%# "Handler1.ashx?ID=" + Eval("ID")%>'  Text='<%# Bind("Image") %>'></asp:Label>--%>
                </ItemTemplate>

                <ItemStyle HorizontalAlign="Left" BackColor ="AliceBlue" />


            </asp:TemplateField>

            <asp:TemplateField HeaderText="Active">
                <EditItemTemplate>
                    <asp:TextBox ID="txtActive" runat="server" CssClass ="TextBox" Text='<%# Bind("Active") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblActive" runat="server" CssClass="bodytext"  Text='<%# Bind("Active") %>'></asp:Label>
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Left" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="CreatedBy">
                <EditItemTemplate>
                    <asp:TextBox ID="txtCreatedBy" runat="server" CssClass ="TextBox"  Text='<%# Bind("CreatedBy") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblCreatedBy" runat="server" CssClass="bodytext"  Text='<%# Bind("CreatedBy") %>'></asp:Label>
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Left" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="CreatedDate">
                <EditItemTemplate>
                    <asp:TextBox ID="txtCreatedDate" runat="server" CssClass ="TextBox"  Text='<%# Bind("CreatedDate") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblCreatedDate" runat="server" CssClass="bodytext"  Text='<%# Bind("CreatedDate") %>'></asp:Label>

                </ItemTemplate>
                <ItemStyle HorizontalAlign="Left" />
            </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="White" ForeColor="#333333" />
            <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="White" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#F7F7F7" />
            <SortedAscendingHeaderStyle BackColor="#487575" />
            <SortedDescendingCellStyle BackColor="#E5E5E5" />
            <SortedDescendingHeaderStyle BackColor="#275353" />
            </asp:GridView><br />
            <asp:FileUpload ID="FileUpload2" runat="server" />
                <asp:Button ID="btnUpdate" runat="server" OnClick="btnUpdate_Click" Text="Update Image" />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <tr>

        <td>

        </div>

            <asp:HyperLink ID="HyperLink1" CssClass ="wishlist " NavigateUrl ="~/TableAdd.aspx" runat="server">AddNew</asp:HyperLink><br /><br />

        </td>
        </tr>
        <asp:label id="Messagelbl" forecolor="Red" CssClass="wishlist" runat="server"/>


    </form>
</body>
</html>



请对此提供帮助.



Please help with this Please

推荐答案


这篇关于是否可以在asp.net的gridview列中放置一个上传图像按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 22:36