473,398 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Gridview and FileUpload ItemTemplate

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>
Jun 27 '08 #1
2 5959
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" <Pa**@discussions.microsoft.comwrote in message
news:A7**********************************@microsof t.com...
>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>

Jun 27 '08 #2
Hi Paul,
"Paul" <Pa**@discussions.microsoft.coma écrit dans le message de
news:A7**********************************@microsof t.com...
>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

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mike P | last post by:
When you use a SqlDataSource to hook up data to a GridView it seems to be to be very inflexible. For example, I want to create my own Delete button with my own code and I also want to create a...
0
by: Mike P | last post by:
Where exactly are the updateparameters of a gridview picked up from? I have created 2 very similar gridviews and given the updateparameters the same names as in my edititemtemplates. Yet this...
0
by: Mike P | last post by:
I am trying to edit a gridview while using paging, but whenever I try to edit a row on a page other than page 1, I get an error. Here is my gridview and my code : <asp:GridView ID="GridView1"...
5
by: NKaufman | last post by:
<asp:GridView ID="Basic" runat="server" DataKeyNames="QuestionID,isHeading" AutoGenerateColumns="false" AllowPaging="true" PageSize="100"> <Columns> <asp:BoundField Visible="false"...
0
by: haina | last post by:
the aspx file as blow <asp:DetailsView Width="100%" ID="dvOrg" runat="server" DataKeyNames="Id" AutoGenerateRows="False" OnModeChanging="dvOrg_ModeChanging" OnItemUpdating="dvOrg_OnItemUpdating" ...
0
by: sharonrao123 | last post by:
hello all, I have a parent gridview company and in this one a nested gridview people, Is it possible to allow the user to select one row or multiple rows from the people gridview using a check box...
1
by: tucson | last post by:
I have a gridview that has a blank row with 2 input fields: file to upload, and a description of the file. They click Add and a new row is added, Remove and the row is removed. The problem is:...
6
by: RobertTheProgrammer | last post by:
Hi folks, Here's a weird problem... I have a nested GridView setup (i.e. a GridView within a GridView), and within the nested GridView I have a DropDownList item which has the...
3
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a gridview with several template columns and a few command button columns, column 1 and 2 are dropdown boxes, column 3 is a checkbox and column 4 is a text box, followed by command button...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.