如何在编辑记录时将FileUpload控件放在gridview中

时间:2014-02-04 13:28:10

标签: asp.net sql sql-server

我在编辑或删除记录时使用griview属性而无需编码

当我点击编辑按钮时,我的图像也会转换为TextBox控件, 我想采取

  

Fileupload控件而不是textBox控件。

因为我设置的属性是什么?

我的代码如下

<asp:GridView ID="GridView1" runat="server" Width="197px" 
     AutoGenerateColumns="False" DataKeyNames="ProductID" 
     DataSourceID="SqlDataSource2" AllowPaging="True">
     <Columns>
          <asp:BoundField DataField="ProductID" HeaderText="ProductID" 
              InsertVisible="False" ReadOnly="True" SortExpression="ProductID" />
          <asp:BoundField DataField="ProductName" HeaderText="ProductName" 
              SortExpression="ProductName" />
          <asp:ImageField DataImageUrlField="Image" HeaderText="PHOTO">
              <ControlStyle Height="100px" Width="100px" />
          </asp:ImageField>
          <asp:BoundField DataField="Status" HeaderText="Status" 
              SortExpression="status" />    
                <asp:CommandField ShowEditButton="True" />
                <asp:CommandField ShowDeleteButton="True" />
     </Columns>
</asp:GridView>

这是SqlDataSource2的代码:

<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionStringnewdb %>" 
            DeleteCommand="delete from Product where ProductID=@ProductID" 
            SelectCommand="SELECT * FROM [Product]" 
            UpdateCommand="update  Product set ProductName=@ProductName,Status=@Status where ProductID=@ProductID ">
            <DeleteParameters>
                <asp:ControlParameter ControlID="GridView1" Name="ProductID" 
                    PropertyName="SelectedValue" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:ControlParameter ControlID="GridView1" Name="ProductName" 
                    PropertyName="SelectedValue" />
                <asp:Parameter Name="ProductID" />
            </UpdateParameters>
</asp:SqlDataSource>     

1 个答案:

答案 0 :(得分:0)

使用EditItemTemplate并添加FileUpload控件:

... other columns ...
</EditItemTemplate>
    <ItemTemplate>
        <asp:FileUpload id="FileUpload1"  runat="server">
   </asp:FileUpload>
    </ItemTemplate>
</asp:TemplateField>
... other columns ...

这是一个教程:http://msdn.microsoft.com/en-us/library/ms972948.aspx