Gridview and FileUpload ItemTemplate

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?UGF1bA==?=

    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_q uotes" runat="server"
    AutoGenerateCol umns="False" CssClass="gv">
    <HeaderStyle CssClass="gv_he ader" />
    <AlternatingRow Style CssClass="gv_al t_row" />
    <Columns>
    <asp:BoundFie ld DataField="line _part_num" HeaderText="SO Part">
    <ItemStyle HorizontalAlign ="Left" />
    <HeaderStyle HorizontalAlign ="Left" />
    </asp:BoundField>
    <asp:TemplateFi eld HeaderText="Ven dor Quote Document">
    <ItemStyle HorizontalAlign ="Center" />
    <HeaderStyle HorizontalAlign ="Center" />
    <ItemTemplate >
    <asp:FileUplo ad ID="fu_vendor_q uote" runat="server"
    /><asp:HyperLi nk ID="lnk_vendor_ quote" runat="server" Target="_blank" />
    </ItemTemplate>
    </asp:TemplateFie ld>
    </Columns>
    </asp:GridView>
  • Teemu Keiski

    #2
    Re: Gridview and FileUpload ItemTemplate

    Hi,

    my post should help you understand the control hierarchy

    Understanding the naming container hierarchy of ASP.NET databound controls


    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_quote s.Rows

    Dim fu_vendor_quote As FileUpload =
    CType(gvRow.Fin dControl("fu_ve ndor_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




    "Paul" <Paul@discussio ns.microsoft.co mwrote in message
    news:A77C8540-96D6-4A48-97EC-0A6BB5B2B2D6@mi crosoft.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_q uotes" runat="server"
    AutoGenerateCol umns="False" CssClass="gv">
    <HeaderStyle CssClass="gv_he ader" />
    <AlternatingRow Style CssClass="gv_al t_row" />
    <Columns>
    <asp:BoundFie ld DataField="line _part_num" HeaderText="SO Part">
    <ItemStyle HorizontalAlign ="Left" />
    <HeaderStyle HorizontalAlign ="Left" />
    </asp:BoundField>
    <asp:TemplateFi eld HeaderText="Ven dor Quote Document">
    <ItemStyle HorizontalAlign ="Center" />
    <HeaderStyle HorizontalAlign ="Center" />
    <ItemTemplate >
    <asp:FileUplo ad ID="fu_vendor_q uote" runat="server"
    /><asp:HyperLi nk ID="lnk_vendor_ quote" runat="server" Target="_blank" />
    </ItemTemplate>
    </asp:TemplateFie ld>
    </Columns>
    </asp:GridView>

    Comment

    • PhilTheGap

      #3
      Re: Gridview and FileUpload ItemTemplate

      Hi Paul,
      "Paul" <Paul@discussio ns.microsoft.co ma écrit dans le message de
      news:A77C8540-96D6-4A48-97EC-0A6BB5B2B2D6@mi crosoft.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.FindContro l("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="TabContaine r1_TabPanel1_Up datePanel1">, 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.FindContro l ("TabContainer1 ") as TabContainer;
      TabPanel tabp = tabc .FindControl ("TabContainer1 ") as TabPanel;

      Hope it helps

      Comment

      Working...