.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Using FileUpload and GridView controls

Posted By:      Posted Date: September 04, 2010    Points: 0   Category :ASP.Net
Hi to all,I have four controls in my page: FileUpload, LinkButton, GridView, and Button.FileUpload - I use the control to browse and open an Excel file in the client machine.LinkButton - I use the control to trigger the method that copies the Excel file to the server, converts the data of Excel file to DataTable, deletes the Excel file, and returns the DataTable.GridView - I use the control to display the data.Button - I use the control to save the data to the database.I did not see any problem until I uploaded the third file that hanged my page. I noticed that every time I upload a file, the page become slower gradually.Each Excel file has 2,000 records, and every time the GridView displays an item, it searches the data on the database. I think, the more the data in the database, the slower the searches can be.To solve this problem, I set the AllowPaging property of GridView to true. The less displaying of items, the less searching of data can be. But, every time I change the page of GridView, I have to bind again the data to the GridView. In order to bind the data, FileUpload must contain the source file, but not because FileUpload frees the file when the page posts back. And I don't want the user browses the file every time he changes the page of GridView. That is very tedious.Does anyone have encountered this kind of problem? Please share us your solution.Your responses

View Complete Post

More Related Resource Links

Accessing the different controls inside a GridView control

how we can access a particular control which resides inside a GridView control. In this article I will show you how you can access different controls inside a GridView control. We will see how we can access a TextBox control, a DropDownList control and a ListBox control. If you are working with ASP.NET 1.X then you might want to check out my article Accessing Different Controls Inside a DataGrid.

How to bind GridView and DropDownList controls using DataTable object

In .net framework 2.0, you can load a DataTable in memory by consuming a data source using a DataReader. In this version you will find the flexibility in accessing the DataReader means write access code once and use again and again using DataReader. To see the functionality of DataTable consider an example that is created using VS2005.

Manually coding controls such as gridview, listview, repeater, etc.


using vs2010 and .net 4

In my project I have a separate DAL built from class files that I'd like to use to store my code for CRUD operations against my database.

I'm having a hard time finding examples of how to code server controls like the gridview, listview, repeater etc., for CRUD operations manually, i.e., without a datasource control of some flavor.

I don't have any problem manually coding the referenced controls to get my data, but I do have problems when it comes to coding them to perform CRUD operations unless I use a datasource control. When I use the datasource controls CRUD operations seem to automagically appear out of nowhere after they're configured.

Can someone point me to some samples somewhere? Have I missed a section at MSDN?


GridView editing without using data source controls?


I am binding my gridview without using a datasource control and instead doing it in the code behind. However, I would like to use the inline editing features of the gridview. Could someone please point me to an example that does gridview editing/updating 'manually' in the code behind?


how do i use javascript to change values of controls inside a gridview

i have 2 labels (lblRate,lblTotal) and a textbox (txtQuantity) in a itemtemplate of a gridview.I want to calculate the products of rate and quantity and show it in Total as the textbox loses focus...i cant use textchanged because i dont want the page to postback.How do i use javascript to achieve this??Please Help Urgently....<asp:TemplateField HeaderText="Rate">                <ItemTemplate>                    <asp:Label ID="lblRate" runat="server" Text='<%# Eval("Rate") %>' />                </ItemTemplate>            </asp:TemplateField> <asp:TemplateField HeaderText="Quantity">                <ItemTemplate>                    <asp:TextBox ID="txtQty" runat="server" />                </ItemTemplate>&

how to apply validation controls on Gridview which is created dynamically

 hi, i created a gridview with two columns and 8 rows dynamically. All the rows are empty and editable at runtime. I am giving column names for this grid from some other .aspx page by passing column names using querystring.Because i am using this grid for three different pairs of column names.  i would like to know how to apply Required Field Validator, Regular Expression Validator  and Range Validator on Gridview textboxes. So that by using those validators i want to validate user inputs. And i would also like to know how to add rows at runtime for this grid. I am using ASP.net 2.0 and C#.net for this.(Visual Studio 2005) The code i am using to create gridview is below. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="LoadData.aspx.cs" Inherits="LoadData" %>  <form id="form1" runat="server">  <div> <asp:GridView ID="GrdDynamic" runat="server" AutoGenerateColumns="False" ForeColor="#333333" BorderColor="GradientInactiveCaption" BorderStyle="Solid" style="z-index: 108; left: 24px; position: absolute; top: 13px">  <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />  <RowStyle BackColor="#EFF3FB"

GridView EditItem FileUpload validation

Hey allI am using a gridview that contains an asp:fileupload so that when the user clicks 'edit' they can upload a pdf. I need to validate the size of the file, it needs to be less then a certain size. I tried to use a custom validator, but it never get called when the user updates. Is there a way to do this? How can I validate the file size on edit in the gridview?Thank youAaron

1st PostBack only: SelectedIndexChanged events fire AND GridView & ReadOnly controls disappear

On initial load of the page, everything is visible & runs correct. On the first PostBack fired by any one of my DDLs, RadioBtns, LinkBtns that have the AutoPostBack=true property, then ddlPriority_SelectedIndexChanged & ddlPendUserReqType_SelectedIndexChanged events always fire (and only from these DDLs, the others don't fire inappropriately), even when neither of those controls had been selected. Then my GridView gridPendRoles disappears, unless a DataSource & DataBind() is forced. Any ReadOnly controls (lblTicketID, txbxInsertTicketDate, lblPendUserID) will also loose their data/text in the first PostBack. However, every PostBack following will not inappropriately fire events. And as long as a DataSource was set & DataBind() called a 2nd time at any time during any PostBack, the GridView will stay visible with correct data displayed. Again, as long as the ReadOnly controls have their data/text set a 2nd time during any PostBack, they too will retain their data/text for every following PostBack. I've tried debugging with Trace on & walked thru everything very thoroughly, but still cannot catch any reasons why this would occur. And since I am using the Delete & Edit command linkBtns in my GridView, I can't just force a DataSource & DataBind() on every PostBack, or I would loose those Row

dropdownlist controls in gridview issue

 the below code creates drop down each time i add a category to the database table. however, i don't wish to have drop down created each time - how can i have all my data in one drop down? thanks...  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CascadingDropDownTestConnectionString %>"  SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Category]">  </asp:SqlDataSource>    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID"  DataSourceID="SqlDataSource1">  <Columns>  <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False"  ReadOnly="True" SortExpression="CategoryID" />  <asp:TemplateField HeaderText="Categories">  <ItemTemplate>  <asp:DropDownList ID="ddlCategories" AutoPostBack="true" DataTextField="CategoryName"  DataValueField="CategoryID" DataSourceID="SqlDataSource1" runat="server" AppendDataBoundItems="true"  SelectedValue='<%# Bind("CategoryID") %>' />  &

How to create templete controls inside a gridview at run time


i am creating a grid view at run time.now i want to create controls inside the gridview at run time itself,and how to Bind/Eval it.

plz help me

On GridView Click, populate other controls with column values


Hello team,

I have 5 controls on the page - textbox, radiobutton, listbox, checkbox, and any other one more. And i have a grid. The grid has 5 corresponding columns. I have to make the grid row clickable, and on the click, i have to populate my 5 controls with each of the corresponding grid column values.

Please let me know how can i make it. I know that i can make the grid clickable, by setting the e.row.attribute.add("OnClick", "javascript:return passValues();");. In this case, all the value passing will happen in javaScript. Is this the correct way? I have yet to try implementing this, not sure if there will be any issues.

Before that wanted to know if there is any other approach to achieve this. Please help!

Gridview Paging resets form controls


Hi all,

I have a gridview which has 4 columns, each holding an ImageButton in a templateField column. When I click on one of these image buttons the clicked upon image is displayed in Image1 using GridView1_RowCommand and this works fine.

However, when I click on one of the page numbers on the gridview the Image1 control resets to its original state and loses its ImageUrl.

Below is the HTML source for the gridview.

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
AutoGenerateColumns="False" DataSourceID="sqlImages" PageSize="1"
<asp:ImageButton ID="ImageButton1" runat="server" Height='75px' Width='150px' ImageUrl='<%# Eval("Col1") %>' CommandArgument='<%# Eval("Col1") %>' />
<asp:ImageButton ID="ImageButton2" runat="server" Height='75px' Width

RowCommand returns null value for controls which are not binded to Gridview source


I am tryting to reach controls in the gridview rows by RowCommand event. I can take values of controls which are binded to gridview source successfully . But for all other controls which is not binded to gridview returns NULL value. All controls run at server. Why is that?

UpdatePanel, GridView and Timer controls used together - OnTick() and DataBind



I am currently working on a page that contains a GridView control which is bound to an ObjectDataSource control.  The ObjectDataSource invokes a method on a DAO layer class that returns a DataTable and all is working just fine.  Paging and Sorting are enabled and work ok as well.  I have "wrapped" the GridView control inside an <UpdatePanel><ContentTemplate> construct and now the Paging and Sorting occur w/o the Page reload as expected - still no problem. 

However, now I want to have the GridView simply refresh itself every 5 to 10 seconds so I placed a Timer control w/ an interval of 5000 milliseconds INSIDE the UpdatePanel.  I am sure there is more that must be wired and have had trouble finding a good article where the UpdatePanel, TimerControl, and GridView control are used together.  Examples that I have seen use Label controls and implement the OnTick event but it is not clear yet to me how to use this w/ a databound control like a GridView.  Can anyone suggest a link or 2 showing an example of this scenario. 

NOTE:  I am not currently programmatically "binding" the GridView control.  The GridView control and ObjectDataSource control are simply bound by setting the DataSourceID property of the GridView to the ID of the ObjectDataSource - they are bou

Databinding on GridView cracks ViewState of controls containing in GridView




My problem is with GridView and is as follows: I have a GridView that has DataTable as its data source. There is also one unbound column containing check boxes, indicating which rows to delete when a Delete button on the form is clicked. In Delete button click event handler I remove selected rows from DataTable, rebind data on GridView. This works as expected. The problem comes when I want to disable header row when GridView is empty (contains zero rows). To do this I call myGridView.HeaderRow.Enabled = false. Actually this call does nothing and as a result I have the header enabled. If I do not do data rebinding on GridView before disabling the header (or changing e.g. "check all" check box to checked state), it works, but rows are not deleted. What can be the problem with disabling the header in my case?

Can a .ASP Page display GridView Controls?



I have been given a site mainly created with .ASP pages with the majority of the data retrieval done via Functions within tables.

I'm trying to move away from this by implementing GridViews etc however my gridview within any .asp page fails to return any data. I can test the query and it works within the query builder section however the empty template view keeps on appearing.

The code is below:

<asp:GridView id="GridView1" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1">
  <asp:BoundField DataField="Openx" HeaderText="Openx" SortExpression="Openx">
  <asp:BoundField DataField="Closex" HeaderText="Closex" SortExpression="Closex">
  No Data
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=RAM;Initial Catalog=Availability;User ID=******;Password=****" ProviderName="System.Data.SqlClient" SelectCommand="SELECT [Openx],

Adding controls to custom extended gridview



I have custom gridview that  inherit from the regular gridview.

On of the features is that is has a built in page size dropdown in an extra header row.

Another feature is that this extra header row has a place holder where aditional controls can be added but here is where I have some problems.

When I add a control that is created outside the gridview to the gridviews builtin placeholder and tries to do anything that performs a postback the gridview dissepears, but appears again on a new post back.

Here is the code for the gridview:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Backend.BLL;
using Backend.DAL;
using Backend.IP;

namespace SharedGui
    public delegate void UpdateEventHandler();

    AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal),
    AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal),
    ToolboxData("<{0}:GridViewCustom runat=\"server\"> </{0}:GridViewCustom>"),
    Description("Extended gridview control")
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend