Accessing child controls inside of a GridView inside of a MultiView

I have a fileupload control which is in a itemtemplate field within the GridView:

 

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="Trk_SqlDataSource">
                                <Columns>
                                    <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                                    <asp:TemplateField HeaderText="Upload Track">
                                        <ItemTemplate>
                                            <asp:FileUpload ID="FileUpload2" runat="server" />
                                            <asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="Upload" />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>

All of this is inside of View2 of a Multiview on a single page.

 

I am trying to access the fileupload control when i click Button4 using this code:

protected void Button4_Click(object sender, EventArgs e)
    {
        string myMusicDirectory = "../media";
        string audioFileName = string.Empty;

        if (((FileUpload)GridView1.FindControl("FileUpload2")).HasFile)
        {
            audioFileName = ((FileUpload)GridView1.FindControl("FileUpload2")).FileName;
            int filesize = ((FileUpload)GridView1.FindControl("FileUpload2")).PostedFile.ContentLength;

            if (filesize > 0)
            {
                string savedAudioFileName = myMusicDirectory + @"/" + Path.GetFileName(audioFileName);
                ((FileUpload)GridView1.FindControl("FileUpload2")).SaveAs(Server.MapPath(savedAudioFileName));
            }
        }
    }

 

and i keep getting the error of:

Error    156    Cannot convert type 'System.Web.UI.Control' to 'FileUpload'

 

I apologize if this has been discussed earlier I tried searching this site and countless others but I'm stumped here. So how do i go about accessing the child controls in the GridView which is inside of a View within a Multiview?

 

Thank you in advance.
 

0
Seanathon
12/8/2006 9:25:51 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

1 Replies
1265 Views

Similar Articles

[PageSpeed] 6
Get it on Google Play
Get it on Apple App Store

Use a recursive control search that can drill down all levels of the control hierarchy

 See several of my previous posts on this

http://forums.asp.net/thread/1171322.aspx


If it was easy, everybody would be doing it.
0
sbyard
12/9/2006 8:55:02 PM
Reply:

Similar Artilces:

Cannot access a dropdownlist control inside the gridview control
I am using the Gridview control without a DataSource control. When I click on the Edit button, the page posts back and enters the following code: <code>     Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing         Try            Dim row As GridViewRow = GridView1.Rows(e.NewEditIndex)            Dim ddlCustomerID As DropDownList...

Problem with TreeView control inside tabs structure and inside MultiView control
I have web parts inside 2 different 'tab' stuctueres.  In the first one I am using a MultiView control to simulate tabs.  In the second case I'm using some basic javascript and and divs to create my tab structure.  In either case, however, the web parts as well as other Atlas enabled controls (controls within an UpdatePanel) do not seem to work.  The web parts do not even render.  And my control in another tab, which is basically a TreeView wrapped in an UpdatePanel, does not function.  It renders but the navigation stops working.  If anybody has ru...

Getting the control id of a control inside gridview control
 uhmm.. a little bit confusing regarding my subject because i dont know how to say it...by the way my problem is how can i get the id of a control (e.g. textbox) inside the gridview... and the textbox is in the templatefield... is there any way i can get its id??  hoping i could get a reply as soon as possible... Regards,MhaeyPlease remember to click “Mark as Answer” on the post that helps you.. =) What do you want's to do by getting the id of the Text box? Do you want's to find particular Textbox with certain id ? Kamran ShahidSr. Software Engineer(MCP,MCAD.net,MC...

FileUpload control inside UpdatePanel inside user control inside popup
Hi,     The Asp.Net File Upload control is not working inside update panel. Acutally i have put the FileUpload control inside User Control again inside update panel. Since the update panel does async postback. The posted file is null in the server side. When i do full page level post back it works. but i have to put it inside update panel. How to do it? Becuase the FileUpload control should be in Ajax Model Popup Extender where i have to put update panel to avoid closing of popup after fullpostback. Since the ajax model popup extender is getting closed after full post b...

Access Controls inside Controls
I have a login control (Login1) inside a Login View control (LoginView1). MembershipUser mbr; mbr = Membership.GetUser(Login1.UserName); It can not find control Login1.  Cheers.  MattSystems Engineer / ASP.NET Web Developermbaughan@raecomputing.com You have to use FindControl. Try creating a local Login control using   LoginView1.FindControl("Login1");Remember: mark posts that helped you as the answer to aid future readersWhy UpdatePanels Are DangerousWhy You Should Not Place Your Whole Site In An UpdatePanel MembershipUser mbr; LoginView1.Find...

Help Req: !!! :- On Disabling Controls Present inside a Gridview control
Hi All, We have A requirement Where we have disable controls inside a grid.These controls can be textbox, DropDownlist (in TemplateField), ComandField present inside the grid.We have to call a generic method for doing the same .(since it can be done for multiple grid.) PFB the code snippet we use. Which disables all the controls inside the page.The bolded part of the code is used to loop inside a grid view.(Not Working.)Is this ideal way to deal with the requirement.Or can someone suggest be a better way.        public void DisableMe(Page p1, st...

Problem Accessing value inside itemtemplate of Gridview with no control inside
I am having a problem to access the value of <%# Eval("item_sku") %> inside ItemTemplate Column. If I use a Label, I don't have any problem to access the control value. Is this a Bug in Asp.net 2.0? The html shows <td></td> tags.             <asp:TemplateField HeaderText="SKU" SortExpression="item_sku">                 <ItemTemplate>                &nb...

How to access a control inside a Repeater control?
 <asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate><ul></HeaderTemplate> <ItemTemplate><li><asp:Image id="Image1" runat="server" /> </li></ItemTemplate> <FooterTemplate></ul></FooterTemplate> </asp:Repeater>   Protected Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound Dim Image1 As WebControls.Image Image1 = CType(e.Item.FindCo...

How to access control inside DataList control?
I have a dataList control that is used to create thumbnails of my images. Inside this dataList I have an Image, HyperLink, and CheckBox controls. I want to access the checkBox controls during run time when the user click on the Delete button. In the btnDelete method, I want to check if the chbDelete control is checked. If it is checked, grab the Text property (which is the file path and file name) and then delete the file off of the image folder. So here's my code.  1 CheckBox chbImageFile = (CheckBox)dtlBrowseImage.FindControl("chbDelete"); 2 3 if (ch...

Calendar Control inside Repeater, Handling Child control events in parent Data Control
Hi all,I've been researching a problem i have for a couple of days now and i'm still not sure how to even start to handle it.I'm essentially trying to build a page that will display custom form fields/controls for individual items/rows inside a repeater.I've got a fairly complex calendar i need to have working inside each individual row of the Repeater. The calendar is set up to fire the following events: OnDayRender="Calendar2_DayRender" OnSelectionChanged="Calendar2_SelectionChanged" OnVisibleMonthChanged="Calendar2_VisibleMonthChanged"My first question is how do i go about handling these...

Accessing controls inside User control template
Hi, I need to create a user control with one template. That template needs to be like View in MultiView or Wizzard control or Panel. It means, that controls, which are inside should be visible to the page. It will be created just once per control. I need to be able to write :  TextBox1.Text = "Hello world" not : (MyUserControl1.Controls.FindControl("TextBox1") as TextBox).Text = "Hello world" Thanks, radco  If this is a answer to your problem, mark it as answer in right upper corner. It helps other who read your article to known that...

Accessing controls inside the content server control
When I select design view for a web form that has a master page, I cannot see the controls in the page, only the controls for the master page.  How do I access the controls I have put inside the content control?   To add an event to the .cs file, I select the control and double-click the event I need from the properites window.  I can no longer select the controls...so how do I add the server side event? Thanks, Bob...

How to access control inside DataList control? #2
Since DataList does not seem to have mode, I can't find a way to access the Image control inside of DataList control.I have tried this:Image imgStaffPic = (Image)DataList1.FindControl("imgStaffImage");imgStaffPic.Visible = false; The error was: Object reference not set to an instance of an object.  So any help is appreciated. Hello, Have you tried using the ItemDataBound Event? Here is a sample I put together for you.  protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e) { if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType...

Access controls inside nested user controls
Hi!  I have no experience with asp.net and I have a default.aspx page with some componentes, a menu and an UpdatePanel with a PlaceHolder inside, according the menu button pressed, I load an ascx page inside the PlaceHolder. Everything works well but inside service.ascx page I have another user control named form.ascx with some normal asp.net controls. The problem is I don´t know how to access componentes inside form.ascx (that is inside service.aspx) from default.aspx.cs. For example: I have a Label named "status" inside for...

Web resources about - Accessing child controls inside of a GridView inside of a MultiView - asp.net.presentation-controls

Highest Percentage Of Opera Mini Users Accessing Facebook? Macau
If you were asked to guess which country had the highest percentage of users of Opera mobile Web browser Opera Mini users accessing Facebook ...

International Users Accessing Facebook Places Through US VPN Accounts
By using a virtual private network (VPN) hosted in the United States, Facebook users from around the world are accessing Facebook Places. The ...

What are some alternatives to Yodlee for accessing bank information?
Clay Loveless , Founder, Jexy. Co-founder, Mashery. Founder, Jexy. Co-founder, Mashery.

Cloud Console - Accessing files in cloud storage for iPad on the iTunes App Store
Get Cloud Console - Accessing files in cloud storage on the App Store. See screenshots and ratings, and read customer reviews.

Meryl Streep On Accessing The Characters Within - YouTube
Meryl Streep talks about the importance of an actors work representing their ability. CONNECT WITH AFI: http://facebook.com/AmericanFilmInstitute ...

Student pleads guilty to accessing records about Frances Abbott design scholarship
The Sydney student who leaked information about a fashion school scholarship controversially awarded to the daughter of the Prime Minister has ...

Accessing a headline opinion
Accessing a headline opinion

Sharp increase in authorities accessing private data
Australian law enforcement and government agencies have sharply increased their access without warrant to vast quantities of private telephone ...

Former librarian charged with accessing student records of Frances Abbott
A former part-time librarian at a Sydney design school has been charged after she allegedly accessed student records of Prime Minister Tony Abbott's ...

Frances Abbott scholarship: Sydney woman pleads guilty to accessing Whitehouse Institute records on PM's ...
A Sydney woman who leaked the student records of Tony Abbott's daughter pleads guilty. A Sydney woman who leaked the student records of Prime ...

Resources last updated: 1/15/2016 2:41:15 PM