Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 5th, 2015, 08:21 PM
Authorized User
Points: 58, Level: 1
Points: 58, Level: 1 Points: 58, Level: 1 Points: 58, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2011
Posts: 14
Thanks: 4
Thanked 0 Times in 0 Posts
Default DetailsView FileUpload Image to SQL

I have tried using the book from pages 384 (CH12) - 473 (CH14) and included review a lot of other code snippets out there on the internet. All to no avail. I have given new meaning to banging your head against a wall...


Here is my aspx page with the detailsview:

Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test2.aspx.cs" Inherits="WebApplication1.test2" %>

<!DOCTYPE html>

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

</head>
<body>
    <form id="form1" runat="server">

        <div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:sqloitmaineConnectionString %>" SelectCommand="SELECT ProblemTitle.ProblemTitle, ProblemDescription.ProblemDescription, ProblemDescription.Image, ProblemDescription.[File], ProblemDescription.FileType, ProblemTypeSecondary.ProblemTypePrimaryNumb, ProblemTypePrimary.ProblemTypePrimary, ProblemTypeSecondary.Id2, ProblemTypePrimary.Id FROM ProblemDescription INNER JOIN ProblemTypeSecondary INNER JOIN ProblemTypePrimary ON ProblemTypeSecondary.ProblemTypePrimaryNumb = ProblemTypePrimary.Id INNER JOIN ProblemTitle ON ProblemTypeSecondary.Id2 = ProblemTitle.ProblemTypeSecondaryNumb ON ProblemDescription.ProblemTitleNumb = ProblemTitle.Id3" InsertCommand="InsertFourTables" InsertCommandType="StoredProcedure">
            <InsertParameters>
                <asp:Parameter Name="Id4" Type="Int32" />
                <asp:Parameter Name="ProblemTitleNumb" Type="Int32" />
                <asp:Parameter Name="ProblemDescription" Type="String" />
                <asp:Parameter Name="FileType" Type="String" />
                <asp:Parameter Name="Id3" Type="Int32" />
                <asp:Parameter Name="ProblemTitle" Type="String" />
                <asp:Parameter Name="Id" Type="Int32" />
                <asp:Parameter Name="ProblemTypePrimary" Type="String" />
                <asp:Parameter Name="Image" Type="String" />
                <asp:Parameter Name="ProblemTypeSecondary" Type="String" />
                <asp:ControlParameter ControlID="DetailsView1$DropDownList2" Name="Id2" PropertyName="SelectedValue" />
                <asp:ControlParameter ControlID="DetailsView1$DropDownList2" Name="ProblemTypePrimaryNumb" PropertyName="SelectedValue" />
            </InsertParameters>
            </asp:SqlDataSource>
        </div>

<div>
    <br />
    <strong>SELECT INSERT TO ADD SUPPORT RECORDS:</strong><br />
    <br />
    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataSourceID="SqlDataSource1" Height="50px" Width="1223px" DefaultMode="Insert" OnItemInserting="DetailsView1_ItemInserting">
        <Fields>
            <asp:TemplateField HeaderText="Primary Problem Type" SortExpression="ProblemTypePrimary">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ProblemTypePrimary") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" DataSourceID="SqlDataSource2" DataTextField="ProblemTypePrimary" DataValueField="Id" AppendDataBoundItems="true" Width="140px">
                        <asp:ListItem Value="-1">-- Primary --</asp:ListItem>
                    </asp:DropDownList>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("ProblemTypePrimary") %>'></asp:Label>
                </ItemTemplate>
                <FooterStyle Wrap="False" />
                <HeaderStyle Wrap="False" />
                <ItemStyle Wrap="False" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Secondary Problem Type" SortExpression="ProblemTypePrimaryNumb">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("ProblemTypePrimaryNumb") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource3" DataTextField="ProblemTypeSecondary" DataValueField="Id2" OnDataBound="dvDropDownList2Model_DataBound" Width="140px">
                        <asp:ListItem Value="-1">-- Secondary --</asp:ListItem>
                    </asp:DropDownList>
            <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:sqloitmaineConnectionString %>" SelectCommand="SELECT Id2, ProblemTypePrimaryNumb, ProblemTypeSecondary FROM ProblemTypeSecondary WHERE (ProblemTypePrimaryNumb = @Id) ORDER BY ProblemTypeSecondary">
                <SelectParameters>
                        <asp:ControlParameter ControlID="DetailsView1$DropDownList1" Name="Id" PropertyName="SelectedValue" />
                </SelectParameters>
            </asp:SqlDataSource>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("ProblemTypePrimaryNumb") %>'></asp:Label>
                </ItemTemplate>
                <FooterStyle Wrap="False" />
                <HeaderStyle Wrap="False" />
                <ItemStyle Wrap="False" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Document Location" SortExpression="FileType">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("FileType") %>' Width="1160px"></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("FileType") %>' Width="1160px"></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("FileType") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="ProblemTitle" SortExpression="ProblemTitle">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("ProblemTitle") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("ProblemTitle") %>' Width="1160px"></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("ProblemTitle") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="ProblemDescription" SortExpression="ProblemDescription">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("ProblemDescription") %>' Height="258px" Width="1160px" TextMode="MultiLine"></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox5" runat="server" Height="528px" Text='<%# Bind("ProblemDescription") %>' Width="1160px" TextMode="MultiLine"></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label5" runat="server" Text='<%# Bind("ProblemDescription") %>'></asp:Label>
                </ItemTemplate>
                <FooterStyle Wrap="False" />
                <HeaderStyle Wrap="False" />
                <ItemStyle Wrap="False" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Image" SortExpression="Image">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Image") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                                       <asp:FileUpload ID="FileUpload1" runat="server" />
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label6" runat="server" Text='<%# Bind("Image") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:CommandField ShowInsertButton="True" />
        </Fields>
    </asp:DetailsView>
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />

</div>
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:sqloitmaineConnectionString %>" SelectCommand="SELECT * FROM [ProblemTypePrimary] ORDER BY [ProblemTypePrimary]"></asp:SqlDataSource>

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


Here is the code-behind:

Code:
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace WebApplication1
{
    public partial class test2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void dvDropDownList2Model_DataBound(object sender, EventArgs e)
        {

            DropDownList DropDownList2Model = (DropDownList)sender;

            DetailsView DetailsView1 = (DetailsView)DropDownList2Model.NamingContainer;

            if (DetailsView1.DataItem != null)
            {

                string strModel = ((DataRowView)DetailsView1.DataItem)["Id2"] as string;

                ListItem lm = DropDownList2Model.Items.FindByValue(strModel);

                if (lm != null) lm.Selected = true;

            }

        }
        protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {

        }
    }
}

I tried rewriting various examples. I could not for the life of me get the LINQ to SQL working. I clicked on the application in my project and added the LINQ to SQL class. When I add a LinqDataSource to my page the list in context objects is insane. It must have 100 entries.

So I opted to use SQLDataSources since that is what I am familiar with.

I found I could never locate the FileUpload object in the code-behind aspx.cs page or I would find the parameters were not being passed to my sql stored procedure.

Everything works fine if I do not upload images to my database, but I wanted to add this feature. Select a file and upload it through the insert sql command when I select the insert button.

Unfortunately it is not that easy with this object because I can't locate it when it is inside the template headers of the aspx page and it needs to be converted to a string (I think) before it is dumped into the image field within the database.

I removed the code-behind and I am starting from scratch again.

Any help would be greatly appreciated.
Reply With Quote
  #2 (permalink)  
Old April 6th, 2015, 12:00 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,957
Thanks: 79
Thanked 1,556 Times in 1,533 Posts
Default

Hi there,

Have you seen this:

http://stackoverflow.com/questions/6...-sqldatasource

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old April 6th, 2015, 11:43 PM
Authorized User
Points: 58, Level: 1
Points: 58, Level: 1 Points: 58, Level: 1 Points: 58, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2011
Posts: 14
Thanks: 4
Thanked 0 Times in 0 Posts
Default Very Helpful

Thank you for the link. That was very helpful!

I am now trying to figure out how to write the code to grab the last record in a database so I can use that [Id3] field as a variable and display it in a textbox. This is what I have so far. I don't mind not using a stored procedure for this, but I started to set one up. Maybe you can help me with this one. Is it also in the 3.5 book? I could not find the answer in there.


Code:
                {
                    string strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["sqloitmaineConnectionString"].ConnectionString;
                    using (SqlConnection con = new SqlConnection(strConnString))
                    {
                        SqlCommand cmd = new SqlCommand("GetLastId3", con);
                        cmd.CommandType = CommandType.StoredProcedure;
                        SqlDataAdapter da = new SqlDataAdapter(cmd);


                        da.Fill(dt);
                        TextBox8.Text = dt.Rows[0][0].ToString();
                        TextBox8.DataBind();
                    }
                }
Reply With Quote
  #4 (permalink)  
Old April 7th, 2015, 03:54 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,957
Thanks: 79
Thanked 1,556 Times in 1,533 Posts
Default

Hi there,

Executing a separate statement to get the last ID is a bad idea. Depending on the load on your server, you may end up with someone else's ID.

Instead, use @identity to get the ID that has just been generated by the insert statement. More details can be found here: http://www.4guysfromrolla.com/articles/100108-1.aspx

BTW: LINQ to SQL, or it's successor Entity Framework makes this a lot easier, so I would reevaluate these technologies and see if you can make them work.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #5 (permalink)  
Old April 7th, 2015, 06:43 AM
Authorized User
Points: 58, Level: 1
Points: 58, Level: 1 Points: 58, Level: 1 Points: 58, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2011
Posts: 14
Thanks: 4
Thanked 0 Times in 0 Posts
Default Great Link!

Wow!

What a great link, thank you!


I want to use LINQ but when I set it up using your book, you should see the list that comes up when I try to use the drop down to select the (I think it is called the class) (in a sql control it would be the data connection). There must be 100 of them. I have no idea why. I did set the data diagram up and I saw the file it created.

I will reexamine this again, hopefully with better luck.
Reply With Quote
  #6 (permalink)  
Old April 9th, 2015, 05:08 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,957
Thanks: 79
Thanked 1,556 Times in 1,533 Posts
Default

>> There must be 100 of them. I have no idea why.

Maybe because you have a large database with many tables and views?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #7 (permalink)  
Old April 12th, 2015, 04:47 PM
Authorized User
Points: 58, Level: 1
Points: 58, Level: 1 Points: 58, Level: 1 Points: 58, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2011
Posts: 14
Thanks: 4
Thanked 0 Times in 0 Posts
Smile Find Control Help

To update where I am at now, I have come very far on my application thanks to your help. I am studying up on the LINQ and I can see the advantages you were talking about. I also purchased your ASP.NET 4.5.1 book and the Microsoft Step by step Visual C# 2013 book. These have helped tremendously!

I am stuck though... I was wondering if you can tell me why I return a null value based on the code provided. I am using a gridview with a fileupload control inside the edititemtemplate. I select a record to edit and then go to the cell with the fileupload control and select my file and click a button to upload that file. I always return a null value on the fileupload control.

Here is the code:

ASPX:

Code:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Width="1500px" DataKeyNames="Id,Id2,Id3,Id4" BackColor="White" BorderColor="Black" BorderStyle="Solid" BorderWidth="5px" CellPadding="3" GridLines="Vertical" style="text-align: center" PageSize="5">
            <AlternatingRowStyle BackColor="Gainsboro" />
            <Columns>
                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <asp:Button ID="editButton" runat="server" commandname="Edit" text="Edit" Width="60px"/>
                        <br /><br /><br />
                        <asp:Button ID="deleteButton" runat="server" CommandName="Delete" Text="Delete" Width="60px" OnClientClick="return confirm('Delete this record?');" />
                    </ItemTemplate>
                    <FooterStyle BorderColor="Black" BorderWidth="3px" />
                    <HeaderStyle BorderColor="Black" BorderWidth="3px" />
                    <ItemStyle BorderColor="Black" BorderWidth="3px" />
                   <EditItemTemplate>
                    <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Id4") %>'></asp:TextBox>
					<asp:Button ID="updateButton" runat="server" commandname="Update" text="Update" Width="60px" />
                        <br /><br /><br />
					<asp:Button ID="cancelButton" runat="server" commandname="Cancel" text="Cancel" Width="60px" />
				    </EditItemTemplate>
                    <FooterStyle BorderColor="Black" BorderWidth="3px" />
                    <HeaderStyle BorderColor="Black" BorderWidth="3px" />
                    <ItemStyle BorderColor="Black" BorderWidth="3px" />
                </asp:TemplateField>
                <asp:BoundField DataField="ProblemTypePrimary" HeaderText="Primary" SortExpression="ProblemTypePrimary" >
                <FooterStyle BorderColor="Black" BorderWidth="3px" />
                <HeaderStyle BorderColor="Black" BorderWidth="3px" />
                <ItemStyle BorderColor="Black" BorderWidth="3px" />
                </asp:BoundField>
                <asp:BoundField DataField="ProblemTypeSecondary" HeaderText="Secondary" SortExpression="ProblemTypeSecondary" >
                <FooterStyle BorderColor="Black" BorderWidth="3px" />
                <HeaderStyle BorderColor="Black" BorderWidth="3px" />
                <ItemStyle BorderColor="Black" BorderWidth="3px" />
                </asp:BoundField>
                <asp:BoundField DataField="ProblemTitle" HeaderText="Title" SortExpression="ProblemTitle" >
                <HeaderStyle BorderColor="Black" BorderWidth="3px" />
                <ItemStyle BorderColor="Black" BorderWidth="3px" Wrap="False" />
                </asp:BoundField>
                <asp:TemplateField HeaderText="Description" SortExpression="ProblemDescription">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Height="250px" Text='<%# Bind("ProblemDescription") %>' TextMode="MultiLine" Width="1168px"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Height="250px" Text='<%# Bind("ProblemDescription") %>' TextMode="MultiLine" Width="1168px"></asp:TextBox>
                    </ItemTemplate>
                    <FooterStyle BorderColor="Black" BorderWidth="3px" />
                    <HeaderStyle BorderColor="Black" BorderWidth="3px" />
                    <ItemStyle BorderColor="Black" BorderWidth="3px" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Document Link" SortExpression="FileType">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox3" runat="server" Height="50px" Text='<%# Bind("FileType") %>' TextMode="MultiLine" Width="500px"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:TextBox ID="TextBox4" runat="server" Height="50px" Text='<%# Bind("FileType") %>' TextMode="MultiLine" Width="500px"></asp:TextBox>
                    </ItemTemplate>
                    <FooterStyle BorderColor="Black" BorderWidth="3px" />
                    <HeaderStyle BorderColor="Black" BorderWidth="3px" />
                    <ItemStyle BorderColor="Black" BorderWidth="3px" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Image" SortExpression="Image">
                    <EditItemTemplate>
                        <asp:FileUpload ID="FileUpload1" runat="server" /><br /><br /><asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Update Image" /><br /><br /><asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Find Controls" />
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Image ID="Image1" runat="server" ImageUrl='<%# "ImageHandler.ashx?Id4=" + Eval("Id4")%>' GridLines="None" Height="120" Width="120" />
                    </ItemTemplate>
                    <FooterStyle BorderColor="Black" BorderWidth="3px" />
                    <HeaderStyle BorderColor="Black" BorderWidth="3px" />
                    <ItemStyle BorderColor="Black" BorderWidth="3px" />
                </asp:TemplateField>
                <asp:BoundField DataField="ProblemTypePrimaryNumb" HeaderText="P Numb" SortExpression="ProblemTypePrimaryNumb" >
                <FooterStyle BorderColor="Black" BorderWidth="3px" />
                <HeaderStyle BorderColor="Black" BorderWidth="3px" />
                <ItemStyle BorderColor="Black" BorderWidth="3px" />
                </asp:BoundField>
                <asp:BoundField DataField="ProblemTypeSecondaryNumb" HeaderText="S Numb" SortExpression="ProblemTypeSecondaryNumb" >
                <FooterStyle BorderColor="Black" BorderWidth="3px" />
                <HeaderStyle BorderColor="Black" BorderWidth="3px" />
                <ItemStyle BorderColor="Black" BorderWidth="3px" />
                </asp:BoundField>
                <asp:BoundField DataField="ProblemTitleNumb" HeaderText="T Numb" SortExpression="ProblemTitleNumb" >
                <FooterStyle BorderColor="Black" BorderWidth="3px" />
                <HeaderStyle BorderColor="Black" BorderWidth="3px" />
                <ItemStyle BorderColor="Black" BorderWidth="3px" />
                </asp:BoundField>
            </Columns>
            <FooterStyle BackColor="#CCCCCC" ForeColor="Black" BorderColor="Black" BorderWidth="3px" />
            <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" BorderColor="Black" BorderWidth="3px" />
            <EditRowStyle BorderColor="Black" BorderWidth="3px" BorderStyle="Solid" />
            <PagerSettings Mode="NumericFirstLast" PageButtonCount="50" Position="TopAndBottom" />
            <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
            <RowStyle BackColor="#EEEEEE" ForeColor="Black" BorderColor="Black" BorderWidth="3px" />
            <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#F1F1F1" />
            <SortedAscendingHeaderStyle BackColor="#0000A9" />
            <SortedDescendingCellStyle BackColor="#CAC9C9" />
            <SortedDescendingHeaderStyle BackColor="#000065" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:sqloitmaineConnectionString %>" SelectCommand="SELECT ProblemTypePrimary.ProblemTypePrimary, ProblemTypeSecondary.ProblemTypeSecondary, ProblemTitle.ProblemTitle, ProblemDescription.ProblemDescription, ProblemDescription.FileType, ProblemTypePrimary.Id, ProblemTypeSecondary.Id2, ProblemTitle.Id3, ProblemDescription.Id4, ProblemTypeSecondary.ProblemTypePrimaryNumb, ProblemTitle.ProblemTypeSecondaryNumb, ProblemDescription.ProblemTitleNumb FROM ProblemDescription INNER JOIN ProblemTypePrimary INNER JOIN ProblemTypeSecondary ON ProblemTypePrimary.Id = ProblemTypeSecondary.ProblemTypePrimaryNumb INNER JOIN ProblemTitle ON ProblemTypeSecondary.Id2 = ProblemTitle.ProblemTypeSecondaryNumb ON ProblemDescription.ProblemTitleNumb = ProblemTitle.Id3"
            UpdateCommand="UpdateFourTables" UpdateCommandType="StoredProcedure" DeleteCommand="DeleteFourTables" DeleteCommandType="StoredProcedure">
            <DeleteParameters>
                <asp:Parameter Name="Id4" Type="Int32" />
                <asp:Parameter Name="Id3" Type="Int32" />
                <asp:Parameter Name="Id" Type="Int32" />
                <asp:Parameter Name="Id2" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="Id4" Type="Int32" />
                <asp:Parameter Name="ProblemTitleNumb" Type="Int32" />
                <asp:Parameter Name="ProblemDescription" Type="String" />
                <asp:Parameter Name="FileType" Type="String" />
                <asp:Parameter Name="Id3" Type="Int32" />
                <asp:Parameter Name="ProblemTitle" Type="String" />
                <asp:Parameter Name="ProblemTypeSecondaryNumb" Type="Int32" />
                <asp:Parameter Name="Id" Type="Int32" />
                <asp:Parameter Name="ProblemTypePrimary" Type="String" />
                <asp:Parameter Name="Id2" Type="Int32" />
                <asp:Parameter Name="ProblemTypePrimaryNumb" Type="Int32" />
                <asp:Parameter Name="ProblemTypeSecondary" Type="String" />
            </UpdateParameters>

        </asp:SqlDataSource>



CODE BEHIND:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace WebApplication1
{
    public partial class crud : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        // This control will search through everything to find a controlid
        private Control FindControlRecursive(Control rootControl, string controlID)
        {
            if (rootControl.ID == controlID) return rootControl;

            foreach (Control controlToSearch in rootControl.Controls)
            {
                Control controlToReturn =
                    FindControlRecursive(controlToSearch, controlID);
                if (controlToReturn != null) return controlToReturn;
            }
            return null;
        }
        protected void Button1_Click(object sender, EventArgs e)
        {

            FileUpload FileUpload1 = (FileUpload)GridView1.FindControl("FileUpload1");

            if (FileUpload1 != null && FileUpload1.HasFile)    // <<--------- Added to remove the stop from the error because it is always NULL

            {
                string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);  // <<-------NULL Object reference not set to an instance of an object

                string contentType = FileUpload1.PostedFile.ContentType;

                using (Stream fs = FileUpload1.PostedFile.InputStream)
                {

                    using (BinaryReader br = new BinaryReader(fs))
                    {

                        byte[] bytes = br.ReadBytes((Int32)fs.Length);

                        string constr = ConfigurationManager.ConnectionStrings["sqloitmaineConnectionString"].ConnectionString;

                        using (SqlConnection con = new SqlConnection(constr))
                        {

                            TextBox TB5 = GridView1.FindControl("TextBox5") as TextBox;
                            var currentrecord = TB5.Text;
                            string query = "INSERT INTO ProblemDescription (Image, ImageName) values (@Data, @ImageName) WHERE Id4=" + currentrecord;

                            using (SqlCommand cmd = new SqlCommand(query))
                            {

                                cmd.Connection = con;

                                //TextBox TB3 = GridView1.FindControl("TextBox3") as TextBox;

                                //cmd.Parameters.AddWithValue("@currentrecord", TB5.Text);
                                cmd.Parameters.AddWithValue("@ImageName", filename);
                                cmd.Parameters.AddWithValue("@Data", bytes);

                                con.Open();

                                cmd.ExecuteNonQuery();

                                con.Close();
                                con.Dispose();

                            }
                        }
                    }
                }
            }
   
            Response.Redirect("crud.aspx");
        }

        //This will find all controls using a button in the aspx page and dump them to screen so you can find the controlID you need
        private void FindAllControls(ControlCollection controls, int depth)
        {

            foreach (Control control in controls)
            {

                // Use the depth parameter to indent the control tree.

                Response.Write(new String('-', depth * 4) + "> ");
                // Display this control.

                Response.Write(control.GetType().ToString() + " - <b>" + control.ID + "</b><br />"); if (control.Controls != null)
                {

                    FindAllControls(control.Controls, depth + 1);

                }

            }

        }

        // This is the button for the find all controls
        protected void Button2_Click(object sender, EventArgs e)
        {

            FindAllControls(Page.Controls, 0);

        }
    }
}

When using my button to display all the controls in the page, because I began looking for the missing values when trying to capture the fileupload information this is what I got in return:


> System.Web.UI.LiteralControl -
> System.Web.UI.HtmlControls.HtmlHead -
----> System.Web.UI.HtmlControls.HtmlTitle -
> System.Web.UI.LiteralControl -
> System.Web.UI.HtmlControls.HtmlForm - form1
----> System.Web.UI.LiteralControl -
----> System.Web.UI.WebControls.Image - Image1
----> System.Web.UI.LiteralControl -
----> System.Web.UI.WebControls.GridView - GridView1
--------> System.Web.UI.WebControls.ChildTable -
------------> System.Web.UI.WebControls.GridViewRow -
----------------> System.Web.UI.WebControls.TableCell -
--------------------> System.Web.UI.WebControls.PagerTable -
------------------------> System.Web.UI.WebControls.TableRow -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.Label -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
------------> System.Web.UI.WebControls.GridViewRow -
----------------> System.Web.UI.WebControls.DataControlFieldHeaderCe ll -
----------------> System.Web.UI.WebControls.DataControlFieldHeaderCe ll -
--------------------> System.Web.UI.WebControls.DataControlLinkButton -
----------------> System.Web.UI.WebControls.DataControlFieldHeaderCe ll -
--------------------> System.Web.UI.WebControls.DataControlLinkButton -
----------------> System.Web.UI.WebControls.DataControlFieldHeaderCe ll -
--------------------> System.Web.UI.WebControls.DataControlLinkButton -
----------------> System.Web.UI.WebControls.DataControlFieldHeaderCe ll -
--------------------> System.Web.UI.WebControls.DataControlLinkButton -
----------------> System.Web.UI.WebControls.DataControlFieldHeaderCe ll -
--------------------> System.Web.UI.WebControls.DataControlLinkButton -
----------------> System.Web.UI.WebControls.DataControlFieldHeaderCe ll -
--------------------> System.Web.UI.WebControls.DataControlLinkButton -
----------------> System.Web.UI.WebControls.DataControlFieldHeaderCe ll -
--------------------> System.Web.UI.WebControls.DataControlLinkButton -
----------------> System.Web.UI.WebControls.DataControlFieldHeaderCe ll -
--------------------> System.Web.UI.WebControls.DataControlLinkButton -
----------------> System.Web.UI.WebControls.DataControlFieldHeaderCe ll -
--------------------> System.Web.UI.WebControls.DataControlLinkButton -
------------> System.Web.UI.WebControls.GridViewRow -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.Button - editButton
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.Button - deleteButton
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.TextBox - TextBox2
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.TextBox - TextBox4
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.Image - Image1
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
------------> System.Web.UI.WebControls.GridViewRow -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.Button - editButton
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.Button - deleteButton
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.TextBox - TextBox2
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.TextBox - TextBox4
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.Image - Image1
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
------------> System.Web.UI.WebControls.GridViewRow -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.Button - editButton
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.Button - deleteButton
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.TextBox - TextBox2
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.TextBox - TextBox4
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.Image - Image1
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
------------> System.Web.UI.WebControls.GridViewRow -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.TextBox - TextBox5
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.Button - updateButton
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.Button - cancelButton
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.WebControls.TextBox -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.WebControls.TextBox -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.WebControls.TextBox -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.TextBox - TextBox1
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.TextBox - TextBox3
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.FileUpload - FileUpload1
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.Button - Button1
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.Button - Button2
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.WebControls.TextBox -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.WebControls.TextBox -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.WebControls.TextBox -
------------> System.Web.UI.WebControls.GridViewRow -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.Button - editButton
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.Button - deleteButton
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.TextBox - TextBox2
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.TextBox - TextBox4
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
--------------------> System.Web.UI.LiteralControl -
--------------------> System.Web.UI.WebControls.Image - Image1
--------------------> System.Web.UI.LiteralControl -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
------------> System.Web.UI.WebControls.GridViewRow -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
----------------> System.Web.UI.WebControls.DataControlFieldCell -
------------> System.Web.UI.WebControls.GridViewRow -
----------------> System.Web.UI.WebControls.TableCell -
--------------------> System.Web.UI.WebControls.PagerTable -
------------------------> System.Web.UI.WebControls.TableRow -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.Label -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----------------------------> System.Web.UI.WebControls.TableCell -
--------------------------------> System.Web.UI.WebControls.DataControlPagerLinkButt on -
----> System.Web.UI.LiteralControl -
----> System.Web.UI.WebControls.SqlDataSource - SqlDataSource1
----> System.Web.UI.LiteralControl -
> System.Web.UI.LiteralControl -




I hope you might let me know where and why I am failing to read the FileUpload control and how to capture it.


Thank you again for all your help!

Last edited by Dark-Star; April 12th, 2015 at 04:50 PM.
Reply With Quote
  #8 (permalink)  
Old April 12th, 2015, 05:04 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,957
Thanks: 79
Thanked 1,556 Times in 1,533 Posts
Default

Is your FileUpload control always null or its PostedFile?

In the former case try handling one of the GridView events such as RowUpdating. That should give you access to the file upload control.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #9 (permalink)  
Old April 12th, 2015, 06:31 PM
Authorized User
Points: 58, Level: 1
Points: 58, Level: 1 Points: 58, Level: 1 Points: 58, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2011
Posts: 14
Thanks: 4
Thanked 0 Times in 0 Posts
Default Info

It is always null (and I feel I have tried everything) days of researching the web and forums for other examples and situations like mine. To no avail.

I tried RowUpdating as well. Here are a few examples with intellisense on so I can capture the information. Always returns NULL.

Code:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            //FileUpload fileUpload = GridView1.Rows[e.RowIndex].FindControl("FileUpload1") as FileUpload;
            //string path = System.IO.Path.Combine(Server.MapPath("Images"), fileUpload.FileName);
            //SqlDataSource1.UpdateParameters["Image"].DefaultValue = File.ReadAllBytes(path);
            
            
            
            //FileUpload FileUpload1 = (FileUpload)GridView1.Rows[e.RowIndex].FindControl("FileUpload1");

            //FileUpload fileUpload = GridView1.Rows[e.RowIndex].FindControl("FileUpload1") as FileUpload;
            //fileUpload.SaveAs(System.IO.Path.Combine(Server.MapPath("Images"), fileUpload.FileName));
            //SqlDataSource1.UpdateParameters["Image"].DefaultValue = "~/Images/" + fileUpload.FileName;
        }

I commented out as I tried different options but I always have intellisense checking my breakpoint and all I return is a NULL value.
Reply With Quote
  #10 (permalink)  
Old April 12th, 2015, 08:55 PM
Authorized User
Points: 58, Level: 1
Points: 58, Level: 1 Points: 58, Level: 1 Points: 58, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2011
Posts: 14
Thanks: 4
Thanked 0 Times in 0 Posts
Default _RowUpdating

Ok, you were right as this was the area I needed to focus on.

_RowUpdating is now working and I am grabbing what I need from the fileupload control.



Can I upload my Image to my sql database at this time? (stream it inside _RowUpdating)?

Or must I process this upload in a specific way inside the _RowUpdating?

Intelitrace is what I was referring to when I was using the Intelisense word in the previous post. Intelitrace is your friend.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fileupload Brykneval ASP.NET 4 General Discussion 1 August 16th, 2011 04:24 PM
FileUpload msomar C# 2008 aka C# 3.0 5 April 12th, 2010 05:44 PM
image and fileupload control bond007 ASP.NET 2.0 Basics 0 April 28th, 2009 01:30 AM
FileUpload and Image controls fraperz ASP.NET 2.0 Professional 1 July 28th, 2007 05:59 AM
Gridview & DetailsView Database Image Issue ayadrocks ASP.NET 2.0 Basics 1 December 27th, 2005 05:50 PM



All times are GMT -4. The time now is 03:29 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.