Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Can you use a htmlFileField on a Datagrid?


Message #1 by "Salvador Gallego" <salvito@h...> on Wed, 29 May 2002 17:13:10
Hi, 

I'm developing a Datagrid, and when I press on the "edit" column it allow 
me to insert Text, I mean, it show me three TextBox which I can edit.

My question is if one of this TextBox could be an htmlFileField (or <input 
type:file..  Control).

If the answer is yes, how could I do that?

Thanks!

salvito@h...
Message #2 by "Lewis Bass" <lewis@t...> on Wed, 29 May 2002 10:21:28 -0600
I do not know about the htmlfilefield tag
but to do custom dropdowns pull lists and multiple textbox tags (and i have
done quite a few)
you have to use a template column

----- Original Message -----
From: "Salvador Gallego" <salvito@h...>
To: "ASP+" <aspx@p...>
Sent: Wednesday, May 29, 2002 5:13 PM
Subject: [aspx] Can you use a htmlFileField on a Datagrid?


> Hi,
>
> I'm developing a Datagrid, and when I press on the "edit" column it allow
> me to insert Text, I mean, it show me three TextBox which I can edit.
>
> My question is if one of this TextBox could be an htmlFileField (or <input
> type:file..  Control).
>
> If the answer is yes, how could I do that?
>
> Thanks!
>
> salvito@h...
>

Message #3 by Feduke Cntr Charles R <FedukeCR@m...> on Wed, 29 May 2002 12:23:13 -0400
Salvador,

	Yes, you can use any control you would like.  A DataGrid, like many
.NET web controls, supports something called templates.  In this particular
case, you want to look at the EditItemTemplate tag:

<asp:DataGrid RunAt="server" Id="myGrid" OnUpdateCommand="myGrid_Save">
	<asp:TemplateColumn>
		<ItemTemplate>
			<asp:Label RunAt="server" 
				Text='<%#
DataBinder.Eval(Container.DataItem, "FileName") %>' />
		</ItemTemplate>
		<EditItemTemplate>
			<asp:HtmlInputFile RunAt="server" Id="myFile" />
		</EditItemTemplate>
	</asp:TemplateColumn>
</asp:DataGrid>

	In your code behind file, you can use the DataGridCommandEventArgs
Item.FindControl("myFile") and cast it as a
System.Web.UI.HtmlControls.HtmlInputFile:

protected void Save(DataGridCommandEventArgs e)
{
	HttpPostedFile someFile 
(HtmlInputFile)e.Item.FindControl("myFile");
	someFile.SaveAs(Server.MapPath("/") + "\somedir\filename.gif");
}

HTH,
- Chuck

-----Original Message-----
From: Salvador Gallego [mailto:salvito@h...]
Sent: Wednesday, May 29, 2002 1:13 PM
To: ASP+
Subject: [aspx] Can you use a htmlFileField on a Datagrid?


Hi, 

I'm developing a Datagrid, and when I press on the "edit" column it allow 
me to insert Text, I mean, it show me three TextBox which I can edit.

My question is if one of this TextBox could be an htmlFileField (or <input 
type:file..  Control).

If the answer is yes, how could I do that?

Thanks!

salvito@h...
Message #4 by "Salvador Gallego" <salvito@h...> on Thu, 30 May 2002 13:07:05
Thanks a lot for your support!,

It been so useful and oriented me. Aniway I'm still not able to make it 
Works, I think the problem must be in the code-behind or something, 
because i'm not using code-behind yet; Aniway, the error I get is:

----

Parser Error 
Description: An error occurred during the parsing of a resource required 
to service this request. Please review the following specific parse error 
details and modify your source file appropriately. 

Parser Error Message: Could not load type 
System.Web.UI.WebControls.HtmlInputFile from assembly System.Web, 
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.

Source Error: 


Line 239:            </ItemTemplate>
Line 240:            <EditItemTemplate>
Line 241:			    <asp:HtmlInputFile RunAt="server" 
Id="myFile" /> ---> Line of error.
Line 242:		    </EditItemTemplate>			
Line 243:			</asp:TemplateColumn>
 

----

I putted the content of your "void Save" procedure on my "dgData_Edit" 
which I call to from my "OnEditCommand=..." of my datagrid.

Now, this is my old <colums> syntaxis on datagrid:

----
         <Columns>
            <asp:TemplateColumn HeaderText="ID">
              <ItemTemplate>
                 <asp:Label id="Name" runat="server" 
                    Text='<%# Container.DataItem("IdF") %>'/>
              </ItemTemplate>
            </asp:TemplateColumn>
            
            <asp:BoundColumn HeaderText="Name" DataField="NomFich" />

            <asp:BoundColumn HeaderText="Link" DataField="Link">
			<ItemStyle Width="250"/>
			</asp:BoundColumn>
            <asp:BoundColumn HeaderText="Description" DataField="DescF" />
            
            <asp:EditCommandColumn
               EditText="Edit"
               CancelText="Cancel"
               UpdateText="Update"
               HeaderText="Edit"/>
            
            <asp:ButtonColumn HeaderText="Delete" text="Delete"
               CommandName="delete" />
         </Columns>
----

Then I put your ItemTemplate Code instead my <asp:BounColumn 
HeaderText="Link"....> in this way:

----
        <asp:TemplateColumn>
            <ItemTemplate>
                <asp:Label RunAt="server" Text='<%#
                DataBinder.Eval(Container.DataItem, "FileName") %>' />
            </ItemTemplate>

            <EditItemTemplate>
		    <asp:HtmlInputFile RunAt="server" Id="myFile" />
	    </EditItemTemplate>			

	</asp:TemplateColumn>
----

And your code-behind where I told you.

But it still not Works, I think this should be because problems to 
recognize the syntax or something.


Any ideas?

Don't worry too much, just if you have any Idea I would be grateful, 
because I haven't find answers in any other forum.

So, Thanks Aniway!

From Spain,
Salvador Gallego.
Message #5 by Feduke Cntr Charles R <FedukeCR@m...> on Thu, 30 May 2002 09:18:18 -0400
Salvador,

	Sorry about that, I haven't used the Html File Input control yet.
Try replacing the line that's giving you an error with:

<input type="file" id="file" />

	If you get a NullReferenceException, then set the file input's RunAt
attribute to "server".

HTH,
- Chuck

-----Original Message-----
From: Salvador Gallego [mailto:salvito@h...]
Sent: Thursday, May 30, 2002 9:07 AM
To: ASP+
Subject: [aspx] RE: Can you use a htmlFileField on a Datagrid?


Thanks a lot for your support!,

It been so useful and oriented me. Aniway I'm still not able to make it 
Works, I think the problem must be in the code-behind or something, 
because i'm not using code-behind yet; Aniway, the error I get is:

----

Parser Error 
Description: An error occurred during the parsing of a resource required 
to service this request. Please review the following specific parse error 
details and modify your source file appropriately. 

Parser Error Message: Could not load type 
System.Web.UI.WebControls.HtmlInputFile from assembly System.Web, 
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.

Source Error: 


Line 239:            </ItemTemplate>
Line 240:            <EditItemTemplate>
Line 241:			    <asp:HtmlInputFile RunAt="server" 
Id="myFile" /> ---> Line of error.
Line 242:		    </EditItemTemplate>			
Line 243:			</asp:TemplateColumn>
 

----

I putted the content of your "void Save" procedure on my "dgData_Edit" 
which I call to from my "OnEditCommand=..." of my datagrid.

Now, this is my old <colums> syntaxis on datagrid:

----
         <Columns>
            <asp:TemplateColumn HeaderText="ID">
              <ItemTemplate>
                 <asp:Label id="Name" runat="server" 
                    Text='<%# Container.DataItem("IdF") %>'/>
              </ItemTemplate>
            </asp:TemplateColumn>
            
            <asp:BoundColumn HeaderText="Name" DataField="NomFich" />

            <asp:BoundColumn HeaderText="Link" DataField="Link">
			<ItemStyle Width="250"/>
			</asp:BoundColumn>
            <asp:BoundColumn HeaderText="Description" DataField="DescF" />
            
            <asp:EditCommandColumn
               EditText="Edit"
               CancelText="Cancel"
               UpdateText="Update"
               HeaderText="Edit"/>
            
            <asp:ButtonColumn HeaderText="Delete" text="Delete"
               CommandName="delete" />
         </Columns>
----

Then I put your ItemTemplate Code instead my <asp:BounColumn 
HeaderText="Link"....> in this way:

----
        <asp:TemplateColumn>
            <ItemTemplate>
                <asp:Label RunAt="server" Text='<%#
                DataBinder.Eval(Container.DataItem, "FileName") %>' />
            </ItemTemplate>

            <EditItemTemplate>
		    <asp:HtmlInputFile RunAt="server" Id="myFile" />
	    </EditItemTemplate>			

	</asp:TemplateColumn>
----

And your code-behind where I told you.

But it still not Works, I think this should be because problems to 
recognize the syntax or something.


Any ideas?

Don't worry too much, just if you have any Idea I would be grateful, 
because I haven't find answers in any other forum.

So, Thanks Aniway!

From Spain,
Salvador Gallego.

  Return to Index