在详细信息视图中使用fileupload作为模板字段

时间:2010-12-30 16:07:28

标签: asp.net vb.net

我有一个管理页面,用户将选择文档路径并将该路径添加到数据库的某个列。我在页面上使用文件上载,他们可以找到文档并复制路径,然后将其粘贴到详细信息视图中。但是,我想跳过这一步,我希望他们选择一个文档,并自动使路径显示在详细信息视图中。

  <asp:FileUpload ID="FileUpload1" runat="server" Visible="False" Width="384px" /><br />
        <br />
        <div>
          <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">

                <ContentTemplate>
                     <center>   <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"
                        DataKeyNames="ID" DataSourceID="SqlDataSource1" Height="128px" Width="544px" Visible="False" OnModeChanged="Button2_Click" CellPadding="4" ForeColor="#333333" GridLines="None" >
                        <Fields>
                                                    <asp:BoundField DataField="Order" HeaderText="Order" SortExpression="Order" />
                            <asp:BoundField DataField="Department" HeaderText="Department" SortExpression="Department"/>
                            <asp:BoundField DataField="DOC_Type" HeaderText="DOC_Type" SortExpression="DOC_Type" />
                            <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                            <asp:BoundField DataField="Revision" HeaderText="Revision" SortExpression="Revision" />
                            <asp:BoundField DataField="DOC" HeaderText="DOC" SortExpression="DOC" />
                            <asp:BoundField DataField="Active" HeaderText="Active" SortExpression="Active" />
                            <asp:BoundField DataField="Rev_Date" HeaderText="Rev_Date" SortExpression="Rev_Date" />
                            <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                                SortExpression="ID" Visible="False" />
                            <asp:CommandField ShowInsertButton="True" />
                        </Fields>
                        <FooterStyle BackColor="#5D7B9D" BorderStyle="None" Font-Bold="True" ForeColor="White" />
                        <CommandRowStyle BackColor="#E2DED6" BorderStyle="None" Font-Bold="True" />
                        <RowStyle BackColor="#F7F6F3" BorderStyle="None" ForeColor="#333333" />
                        <FieldHeaderStyle BackColor="#E9ECF1" BorderStyle="None" Font-Bold="True" />
                        <EmptyDataRowStyle BorderStyle="None" />
                        <PagerStyle BackColor="#284775" BorderStyle="None" ForeColor="White" HorizontalAlign="Center" />
                        <HeaderStyle BackColor="#5D7B9D" BorderStyle="None" Font-Bold="True" ForeColor="White" />
                        <InsertRowStyle BorderStyle="None" />
                        <EditRowStyle BackColor="#999999" BorderStyle="None" />
                        <AlternatingRowStyle BackColor="White" BorderStyle="None" ForeColor="#284775" />
                    </asp:DetailsView>
                         &nbsp;
                    <br />

我需要将fileupload1放入DOC contenttemplate区域,因此它不会显示一个空的文本框,而只会显示一个文本框,它将显示fileupload alt text

alt text

1 个答案:

答案 0 :(得分:0)

我不确定这是否有帮助,但这是一个开始:

<asp:TemplateField HeaderText="DOC">
    <InsertItemTemplate>
        <asp:FileUpload ID="FileUploadDOC" runat="server" Width="384px" />
    </InsertItemTemplate>
</asp:TemplateField>

在Codebehind中,您可以通过以下方式设置doc-path:

Private Sub DetailsView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles DetailsView1.ItemInserting
    Dim FileUploadDOC As FileUpload = DirectCast(Me.DetailsView1.FindControl("FileUploadDOC"), FileUpload)
    e.Values("DOC") = FileUploadDOC.PostedFile.FileName
End Sub