Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Gridview and FileUpload ItemTemplate

Reply
Thread Tools

Gridview and FileUpload ItemTemplate

 
 
Paul
Guest
Posts: n/a
 
      05-29-2008
I have a gridview with 2 columns.

One column is a BoundColumn to a part number (string).
One column is an ItemTemplate with a FileUpload control.

There can be multiple rows (i.e. part numbers) in the gridview.

The user attaches a file for each part number / row.

The user clicks a button after attaching all the needed files.

I am having a problem accessing the FileUpload properties after the button's
OnClick event.

I have looked at the FindControl method, but I am having a hard time
determining the correct control name.

To make things more complicated, I am also using master pages, which modify
the control's name based on the number of rows in the gridview.

Can anyone point me to an example of this scenario?

TIA

Here is the gridview code:

<asp:GridView ID="gv_vendor_quotes" runat="server"
AutoGenerateColumns="False" CssClass="gv">
<HeaderStyle CssClass="gv_header" />
<AlternatingRowStyle CssClass="gv_alt_row" />
<Columns>
<asp:BoundField DataField="line_part_num" HeaderText="SO Part">
<ItemStyle HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:TemplateField HeaderText="Vendor Quote Document">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:FileUpload ID="fu_vendor_quote" runat="server"
/><asp:HyperLink ID="lnk_vendor_quote" runat="server" Target="_blank" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      05-29-2008
Hi,

my post should help you understand the control hierarchy

Understanding the naming container hierarchy of ASP.NET databound controls
http://aspadvice.com/blogs/joteke/ar...-controls.aspx

Essential is to realize that GridView and its rows are naming containers
which provide a new naming scope for controls hey contain (allowing the
controls to have duplicate IDs as long as IDs are unique in the local naming
scope). But the rendered ID matches controls ClientID property and name
attribute to UniqueID property , but the ID is still ID in the local scope.

E.g you can for example loop through GridView's Rows, locate the FileUpload
on every row, and do what you need to do with it

For Each gvRow As GridViewRow in gv_vendor_quotes.Rows

Dim fu_vendor_quote As FileUpload =
CType(gvRow.FindControl("fu_vendor_quote"), FileUpload)
'Here do what you need to do, you can also get row-level data from
gvRow, access DataKeys etc

Next

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net


"Paul" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have a gridview with 2 columns.
>
> One column is a BoundColumn to a part number (string).
> One column is an ItemTemplate with a FileUpload control.
>
> There can be multiple rows (i.e. part numbers) in the gridview.
>
> The user attaches a file for each part number / row.
>
> The user clicks a button after attaching all the needed files.
>
> I am having a problem accessing the FileUpload properties after the
> button's
> OnClick event.
>
> I have looked at the FindControl method, but I am having a hard time
> determining the correct control name.
>
> To make things more complicated, I am also using master pages, which
> modify
> the control's name based on the number of rows in the gridview.
>
> Can anyone point me to an example of this scenario?
>
> TIA
>
> Here is the gridview code:
>
> <asp:GridView ID="gv_vendor_quotes" runat="server"
> AutoGenerateColumns="False" CssClass="gv">
> <HeaderStyle CssClass="gv_header" />
> <AlternatingRowStyle CssClass="gv_alt_row" />
> <Columns>
> <asp:BoundField DataField="line_part_num" HeaderText="SO Part">
> <ItemStyle HorizontalAlign="Left" />
> <HeaderStyle HorizontalAlign="Left" />
> </asp:BoundField>
> <asp:TemplateField HeaderText="Vendor Quote Document">
> <ItemStyle HorizontalAlign="Center" />
> <HeaderStyle HorizontalAlign="Center" />
> <ItemTemplate>
> <asp:FileUpload ID="fu_vendor_quote" runat="server"
> /><asp:HyperLink ID="lnk_vendor_quote" runat="server" Target="_blank" />
> </ItemTemplate>
> </asp:TemplateField>
> </Columns>
> </asp:GridView>



 
Reply With Quote
 
 
 
 
PhilTheGap
Guest
Posts: n/a
 
      05-29-2008
Hi Paul,
"Paul" <(E-Mail Removed)> a écrit dans le message de
news:(E-Mail Removed)...
>I have a gridview with 2 columns.
>
> One column is a BoundColumn to a part number (string).
> One column is an ItemTemplate with a FileUpload control.
>
> There can be multiple rows (i.e. part numbers) in the gridview.
>
> The user attaches a file for each part number / row.
>
> The user clicks a button after attaching all the needed files.
>
> I am having a problem accessing the FileUpload properties after the
> button's
> OnClick event.
>
> I have looked at the FindControl method, but I am having a hard time
> determining the correct control name.

The FindControl method must be called with the Parent control... So if you
write Page.FindControl("FileUpload1") , it returns something if the
FileUpload is inside the Page. But as you use a MasterPage, it is not the
case.

You should load your html aspx page, then take a look at the source page.
You will then find something like "<div
id="TabContainer1_TabPanel1_UpdatePanel1">, which tells you that the
UpdatePanel1 control is inside the TabPanel1 control, which is inside the
TabContainer1 control, which is inside the Page. To get a handle on
TabPanel1, you should write:

TabContainer tabc = Page.FindControl ("TabContainer1") as TabContainer;
TabPanel tabp = tabc .FindControl ("TabContainer1") as TabPanel;

Hope it helps

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XPath if statement and GridView <ItemTemplate> Problem =?Utf-8?B?T3Bh?= ASP .Net 3 11-01-2006 11:08 PM
Gridview Headers for ItemTemplate and EditTemplate theWizard1 ASP .Net Web Controls 0 09-15-2006 08:16 PM
ObjectDataSource, GridView and ItemTemplate Mogens Nielsen - Elbek & Vejrup A/S ASP .Net Web Controls 4 03-24-2006 08:59 AM
How to identify which row to be selected in itemtemplate column under gridview? ABC ASP .Net 1 10-07-2005 06:12 AM
can code inside a Repeater's ItemTemplate modify controls in the ItemTemplate? Bennett Haselton ASP .Net 1 09-24-2004 01:59 AM



Advertisments