Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Generally i had develop the application with gridview but my intention gridview edit update delete.in that gridview i had used fileupload control .this control are visible only whenever edit event performed.actually i had the images and videos in gridview thats why i had used 2 fileupload controls in the gridview.while writing the code in code behind file fileupload controls id will not shown in intellisense

my code:
ASP.NET
<pre><asp:GridView ID="GridView1" runat="server" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowDeleting="GridView1_RowDeleting" AutoGenerateColumns="false" style="height: 664px; width: 624px; z-index: 1; left: 335px; top: 452px; position: absolute" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None">
        <RowStyle Height="100px"  Width="100px"  />
           <AlternatingRowStyle BackColor="PaleGoldenrod" />
          <Columns>
           <asp:BoundField DataField="alphabet_id" HeaderText="id" ReadOnly="true" />
           <asp:BoundField DataField="letter" HeaderText="Alphabetname" ReadOnly="true" />
           <asp:TemplateField  HeaderText="example" HeaderStyle-Width="100px">
               <ItemTemplate>
                   <asp:FileUpload ID="fileUpload1" runat="server" Visible="false" />
                   <br />
                   <asp:Button runat="server" ID="btnload1" Text="Uploadimage" Visible="false" OnClick="btnload1_Click" />
                   <asp:Image ID="Image1"   runat="server" ImageUrl='<%# Bind("example") %>' Width="100px"/>
               </ItemTemplate>
           </asp:TemplateField>
           <asp:TemplateField HeaderText="expression" HeaderStyle-Width="100px">
               <ItemTemplate>
                    <asp:FileUpload  ID="fpload" runat="server" Visible="false"/>
                   <br />
                   <asp:Button runat="server" ID="btnload" Text="uploadvideo" Visible="false" />
                   <video width="200" height="200" controls="controls">
                      <source src="<%# Eval("letter") %>"  type="video/mp4" />
               </ItemTemplate>
           </asp:TemplateField>
              <asp:TemplateField HeaderText="Edit">
              <ItemTemplate>
                 <asp:LinkButton ID="btnEdit" runat="server" CausesValidation="false" CommandName="Edit" Text="Edit"></asp:LinkButton>
              </ItemTemplate>
          </asp:TemplateField>
           <asp:TemplateField HeaderText="Update">
              <ItemTemplate>
                <asp:LinkButton ID="lnkbtnUpdate" runat="server" CausesValidation="true" Text="Update" CommandName="Update"></asp:LinkButton>
              </ItemTemplate>
          </asp:TemplateField>
           <asp:TemplateField HeaderText="Delete">
              <ItemTemplate>
                 <asp:LinkButton ID="lnkbtnCancel" runat="server" CausesValidation="false" Text="Cancel" CommandName="Cancel"></asp:LinkButton>
              </ItemTemplate>
          </asp:TemplateField>

       </Columns>
          <FooterStyle BackColor="Tan" />
          <HeaderStyle BackColor="Tan" Font-Bold="True" />
          <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
          <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
          <SortedAscendingCellStyle BackColor="#FAFAE7" />
          <SortedAscendingHeaderStyle BackColor="#DAC09E" />
          <SortedDescendingCellStyle BackColor="#E1DB9C" />
          <SortedDescendingHeaderStyle BackColor="#C2A47B" />
      </asp:GridView>



Code behind file

C#
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UpdateAlphabets : System.Web.UI.Page
{
   
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindData();
        }
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        BindData();
        FileUpload fup = GridView1.Rows[e.NewEditIndex].FindControl("fpload1") as FileUpload;
        FileUpload fup1 = GridView1.Rows[e.NewEditIndex].FindControl("fpload") as FileUpload;
        Button btn = (Button)GridView1.Rows[e.NewEditIndex].FindControl("btnload1");
        Button btn1 = (Button)GridView1.Rows[e.NewEditIndex].FindControl("btnload");
        fup.Visible = true;
        fup1.Visible = true;
        btn.Visible = true;
        btn1.Visible = true;


       //e.Row.Cells[3].Visible = false;
       //e.Row.Cells[5].Visible = false;
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {

    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

    }

    public void BindData()
    {
        SqlConnection con1 = new SqlConnection(WebConfigurationManager.ConnectionStrings["con1"].ToString());
        SqlDataAdapter da = new SqlDataAdapter("select * from alphabet", con1);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }

    protected void btnload1_Click(object sender, EventArgs e)
    {
        
    }
}



i can't write the code in btnload1_Click event because fileupload controld id's not show in intellisense

Already restart visual studio and operating system but i have same problem.

please help me.

thank u.

What I have tried:

Generally i had develop the application with gridview but my intention gridview edit update delete.in that gridview i had used fileupload control .this control are visible only whenever edit event performed.actually i had the images and videos in gridview thats why i had used 2 fileupload controls in the gridview.while writing the code in code behind file fileupload controls id will not shown in intellisense
Posted
Updated 21-Feb-17 22:43pm
v5

1 solution

The reason is they are inside GridView and when rendered on browser, there will be many FileUpload controls because each row contains them.

So, to identify them in code behind you have to use FindControl.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900