[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

Browse/Upload File from Datagrid Template Column

Hi Experts,

I've put together a Datagrid that is used for displaying, editing and deleting records. One of the fields in the database keeps track of file names.

What I would like to add is a header row that allows a user to browse for a file, upload it, then add the filename to a field in my database.

It would look like this

CategoryColumn        TitleColumn         FiletoUploadColumn
userinput                   userinput            userinput                    uploadbutton     submitbutton

I have this functionality on a separate page, but I'd like to add it to my datagrid.

Is this possible?  

If so, does anyone have any good links that might help me out.

I haven't been able to add this control and I haven't been able to figure out why.

If there are any takers, I'll up the points and provide my messy code.
0
TCantrell
Asked:
TCantrell
  • 3
1 Solution
 
davidlars99Commented:
consider doing something like this

                  <asp:datagrid id="dg1" runat="server" AutoGenerateColumns="false" oneditcommand="edit_function">
                        <columns>
                              <asp:templatecolumn>
                                    <headertemplate>
                                          Column Name
                                    </headertemplate>
                                    <itemtemplate>
                                          <%# Container.DataItem("database_column_name") %>
                                    </itemtemplate>
                                    <edititemtemplate>
                                          <input type="file" id="file1" runat="server" name="file1" />
                                    </edititemtemplate>
                              </asp:templatecolumn>
                              <asp:editcommandcolumn edittext="Edit" canceltext="Cancel" updatetext="Update" />
                              <asp:buttoncolumn buttontype="linkbutton" commandname="delete" text="Delete" />
                        </columns>
                  </asp:datagrid>
0
 
davidlars99Commented:
if you have northwind database here's the dirtiest and most ridiculous example  :)


<%@ Page Language="vb" AutoEventWireup="true"%>
<HTML>
<HEAD>            
<script language="vb" runat="server">
      
            Sub Page_Load(s as object,e as eventargs)
                Dim cn As New System.Data.SqlClient.SqlConnection("data source=(local);uid=xxxx;password=xxxxxx;initial catalog=northwind")
                  Dim da As New system.data.SqlClient.SqlDataAdapter("select contactname from customers", cn)
                  Dim ds As New system.data.DataSet

                  da.Fill(ds)
                  dg1.DataSource = ds
                  dg1.DataBind()
            end sub
            
            Sub dg_Edit(o As Object, e As DataGridCommandEventArgs)      
                  dg1.EditItemIndex=e.Item.ItemIndex            
                  Dim cn As New System.Data.SqlClient.SqlConnection("data source=(local);uid=xxxx;password=xxxxxx;initial catalog=northwind")
                  Dim da As New system.data.SqlClient.SqlDataAdapter("select contactname, contacttitle from customers", cn)
                  Dim ds As New system.data.DataSet

                  da.Fill(ds)
                  dg1.DataSource = ds
                  dg1.DataBind()
            End Sub            
      
      </script>
      </HEAD>
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
                  <asp:datagrid id="dg1" runat="server" AutoGenerateColumns="false" oneditcommand="dg_Edit">
                        <columns>
                              <asp:templatecolumn>
                                    <headertemplate>
                                          column name
                                    </headertemplate>
                                    <itemtemplate>
                                          <%# Container.DataItem("contacttitle") %>
                                    </itemtemplate>
                                    <edititemtemplate>
                                          <input type="file" id="file1" runat="server" name="file1" />
                                    </edititemtemplate>
                              </asp:templatecolumn>
                              <asp:editcommandcolumn edittext="Edit" canceltext="Cancel" updatetext="Update" />
                              <asp:buttoncolumn buttontype="linkbutton" commandname="delete" text="Delete" />
                        </columns>
                  </asp:datagrid>
            </form>
      </body>
</HTML>
0
 
TCantrellAuthor Commented:
Thanks this should get me started.

Just what I was looking for.
0
 
davidlars99Commented:
you're welcome! I'm glad I could help
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now