开发者

help using file upload in details view

I am trying to use a fileupload, to add rows to my gridview on this page. This page is basically a simple admin panel where I can add data to my database. The file upload is used to grab the path of the file and upload the path to the database not the file. The problem is whenever i run my program pick a file, it uploads fine expect the path shows up as true not as the path. I would really appreciate help this is my entire code. the gridview and details view both use the same sqladapater

help using file upload in details view

   <form id="form1" runat="server">


        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <br />
        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem>MSD</asp:ListItem>
            <asp:ListItem>OPS</asp:ListItem>
        </asp:DropDownList>
        <asp:Button ID="Button3" runat="server" Text="Department" />
                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="New" />&nbsp;<asp:Button
                        ID="Button4" runat="server" Text="Cancel" />&nbsp;
                     <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"  CellPadding="4" ForeColor="#333333" GridLines="None" OnModeChanged="Button1_Click"  >
                        <Fields>
                            <asp:TemplateField HeaderText="Order" SortExpression="Order">
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Order") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <InsertItemTemplate>
                                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Order") %>'></asp:TextBox>
                                </InsertItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("Order") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Department" SortExpression="Department">
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Department") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <InsertItemTemplate>
                                    <asp:TextBox ID="textboxdepartment" runat="server" Text='<%# Bind("Department") %>'></asp:TextBox>
                                </InsertItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("Department") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="DOC_Type" SortExpression="DOC_Type">
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("DOC_Type") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <InsertItemTemplate>
                                    <asp:TextBox ID="textboxtype" runat="server" Text='<%# Bind("DOC_Type") %>'></asp:TextBox>
                                </InsertItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label5" runat="server" Text='<%# Bind("DOC_Type") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                            <asp:TemplateField HeaderText="Revision" SortExpression="Revision">
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("Revision") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <InsertItemTemplate>
                                    <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Revision") %>'></asp:TextBox>
                                </InsertItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="textboxrevision" runat="server" Text='<%# Bind("Revision") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="DOC">
                                <EditItemTemplate>
                                    <asp:TextBox ID="textboxdate" runat="server" Text='<%# Bind("DOC") %>'></asp:TextBox>
                                </EditItemTemplate>

                                  <InsertItemTemplate>
        <asp:FileUpload ID="FileUploadDOC" runat="server" Width="384px" Enabled='<%# Bind("DOC") %>'  />
    </InsertItemTemplate>


                                <ItemTemplate>
                                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("DOC") %>'></asp:Label>
                                </ItemTemplate>


                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Active" SortExpression="Active">
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("Active") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <InsertItemTemplate>
                                    <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("Active") %>'></asp:TextBox>
                                </InsertItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label7" runat="server" Text='<%# Bind("Active") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Rev_Date" SortExpression="Rev_Date">
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Rev_Date") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <InsertItemTemplate>
                                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Rev_Date") %>'></asp:TextBox>
                                </InsertItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("Rev_Date") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                                SortExpression="ID" Visible="False" />
                            <asp:CommandField ShowInsertButton="True" ShowCancelButton="False" />
                        </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 />
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
                        DataSourceID="SqlDataSource1">
                        <Columns>
                            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                            <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" />
                        </Columns>
                    </asp:GridView>
                                      <br />

                    &nbsp;</ContentTemplate>
            </asp:UpdatePanel>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CABCIntranetConnectionString %>"
                        DeleteCommand="DELETE FROM [sop] WHERE [ID] = @original_ID AND (([Order] = @original_Order) OR ([Order] IS NULL AND @original_Order IS NULL)) AND (([Department] = @original_Department) OR ([Department] IS NULL AND @original_Department IS NULL)) AND (开发者_开发知识库([DOC Type] = @original_DOC_Type) OR ([DOC Type] IS NULL AND @original_DOC_Type IS NULL)) AND (([Title] = @original_Title) OR ([Title] IS NULL AND @original_Title IS NULL)) AND (([Revision] = @original_Revision) OR ([Revision] IS NULL AND @original_Revision IS NULL)) AND (([DOC] = @original_DOC) OR ([DOC] IS NULL AND @original_DOC IS NULL)) AND (([Rev Date] = @original_Rev_Date) OR ([Rev Date] IS NULL AND @original_Rev_Date IS NULL)) AND (([Active] = @original_Active) OR ([Active] IS NULL AND @original_Active IS NULL))" InsertCommand="INSERT INTO [sop] ([Order], [Department], [DOC Type], [Title], [Revision], [DOC], [Rev Date], [Active]) VALUES (@Order, @Department, @DOC_Type, @Title, @Revision, @DOC, @Rev_Date, @Active)"
                        SelectCommand="SELECT [Order], [Department], [DOC Type] AS DOC_Type, [Title], [Revision], [DOC], [Rev Date] AS Rev_Date, [Active], [ID] FROM [sop] WHERE ([Department] = @Department) ORDER BY [Order]" UpdateCommand="UPDATE [sop] SET [Order] = @Order, [Department] = @Department, [DOC Type] = @DOC_Type, [Title] = @Title, [Revision] = @Revision, [DOC] = @DOC, [Rev Date] = @Rev_Date, [Active] = @Active WHERE [ID] = @original_ID AND (([Order] = @original_Order) OR ([Order] IS NULL AND @original_Order IS NULL)) AND (([Department] = @original_Department) OR ([Department] IS NULL AND @original_Department IS NULL)) AND (([DOC Type] = @original_DOC_Type) OR ([DOC Type] IS NULL AND @original_DOC_Type IS NULL)) AND (([Title] = @original_Title) OR ([Title] IS NULL AND @original_Title IS NULL)) AND (([Revision] = @original_Revision) OR ([Revision] IS NULL AND @original_Revision IS NULL)) AND (([DOC] = @original_DOC) OR ([DOC] IS NULL AND @original_DOC IS NULL)) AND (([Rev Date] = @original_Rev_Date) OR ([Rev Date] IS NULL AND @original_Rev_Date IS NULL)) AND (([Active] = @original_Active) OR ([Active] IS NULL AND @original_Active IS NULL))" ConflictDetection="CompareAllValues" OldValuesParameterFormatString="original_{0}">
                        <DeleteParameters>
                            <asp:Parameter Name="original_ID" Type="Int32" />
                            <asp:Parameter Name="original_Order" Type="Int32" />
                            <asp:Parameter Name="original_Department" Type="String" />
                            <asp:Parameter Name="original_DOC_Type" Type="String" />
                            <asp:Parameter Name="original_Title" Type="String" />
                            <asp:Parameter Name="original_Revision" Type="Int32" />
                            <asp:Parameter Name="original_DOC" Type="String" />
                            <asp:Parameter Name="original_Rev_Date" Type="String" />
                            <asp:Parameter Name="original_Active" Type="String" />
                        </DeleteParameters>
                        <UpdateParameters>
                            <asp:Parameter Name="Order" Type="Int32" />
                            <asp:Parameter Name="Department" Type="String" />
                            <asp:Parameter Name="DOC_Type" Type="String" />
                            <asp:Parameter Name="Title" Type="String" />
                            <asp:Parameter Name="Revision" Type="Int32" />
                            <asp:Parameter Name="DOC" Type="String" />
                            <asp:Parameter Name="Rev_Date" Type="String" />
                            <asp:Parameter Name="Active" Type="String" />
                            <asp:Parameter Name="original_ID" Type="Int32" />
                            <asp:Parameter Name="original_Order" Type="Int32" />
                            <asp:Parameter Name="original_Department" Type="String" />
                            <asp:Parameter Name="original_DOC_Type" Type="String" />
                            <asp:Parameter Name="original_Title" Type="String" />
                            <asp:Parameter Name="original_Revision" Type="Int32" />
                            <asp:Parameter Name="original_DOC" Type="String" />
                            <asp:Parameter Name="original_Rev_Date" Type="String" />
                            <asp:Parameter Name="original_Active" Type="String" />
                        </UpdateParameters>
                        <InsertParameters>
                            <asp:Parameter Name="Order" Type="Int32" />
                            <asp:Parameter Name="Department" Type="String" />
                            <asp:Parameter Name="DOC_Type" Type="String" />
                            <asp:Parameter Name="Title" Type="String" />
                            <asp:Parameter Name="Revision" Type="Int32" />
                            <asp:Parameter Name="DOC" Type="String" />
                            <asp:Parameter Name="Rev_Date" Type="String" />
                            <asp:Parameter Name="Active" Type="String" />
                        </InsertParameters>
                        <SelectParameters>
                            <asp:ControlParameter ControlID="DropDownList1" DefaultValue="MSD" Name="Department"
                                PropertyName="SelectedValue" Type="String" />
                        </SelectParameters>
                    </asp:SqlDataSource>
        </div>
    </form>
</body>
</html>




Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Data
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        DetailsView1.Visible = True
        DetailsView1.ChangeMode(DetailsViewMode.Insert)


        Dim tbox As TextBox = TryCast(DetailsView1.FindControl("textbox1"), TextBox)
        tbox.Text = DateTime.Now.ToShortDateString()



        Dim tbox1 As TextBox = TryCast(DetailsView1.FindControl("textboxdepartment"), TextBox)
        tbox1.Text = DropDownList1.SelectedItem.Text




        Dim tbox2 As TextBox = TryCast(DetailsView1.FindControl("textbox6"), TextBox)
        tbox2.Text = "True"




        Dim tbox3 As TextBox = TryCast(DetailsView1.FindControl("textboxtype"), TextBox)
        tbox3.Text = "S.O.P"


        Dim tbox4 As TextBox = TryCast(DetailsView1.FindControl("textbox5"), TextBox)
        tbox4.Text = "1"


        Dim tbox5 As TextBox = TryCast(DetailsView1.FindControl("textbox2"), TextBox)
        tbox5.Text = GridView1.Rows.Count + 1



    End Sub
    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        UpdatePanel1.Update()
    End Sub

    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
        DetailsView1.Visible = False
    End Sub

End Class


The way that you want to do this will not work in most recent browsers--they do not send the full client path information when you upload the file. Only earlier versions of Internet Explorer and a few others do that.

One way that seems to work is to use a Java applet to pick the file instead of the native file upload widget. Since you only need the path to the file and not the actual file itself, this is an even better solution (no need to upload the file to the server).

Here's a link to a discussion and link to a demo of this working. Please read the comments as well. You'll have to look at the source for the demo page (as well as the source of the linked js file) to see how to make it work.

Just in case that page disappears, I'll copy the relevant links below:

  • Link to demo page
  • Link to original mozilla bug comment with java applet source reference
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜