473,406 Members | 2,620 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,406 software developers and data experts.

gridview problem

115 100+
hello friend
i need urgent help

this is my aspx page
Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Reguserdetailstest.aspx.cs" Inherits="Reguserdetailstest" %>
  3.  
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5.  
  6. <html xmlns="http://www.w3.org/1999/xhtml" >
  7. <head runat="server">
  8.     <title>Untitled Page</title>
  9. </head>
  10. <body>
  11.     <form id="form1" runat="server">
  12.     <div>
  13.         <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
  14.     <asp:GridView ID="reguserDataGridView" runat="server" AllowPaging="True" AllowSorting="True"
  15.                         AutoGenerateColumns="False" BorderStyle="None" CellPadding="2" CellSpacing="1"
  16.                         CssClass="grid"  GridLines="None" Width="100%" Visible="True" PageSize="25" OnPageIndexChanging="gridView_PageIndexChanging">
  17.                         <FooterStyle BackColor="#CCCC99" />
  18.                         <RowStyle CssClass="gridrow" Height="20px" />
  19.                         <EmptyDataTemplate>
  20.                             <strong style="color: red">
  21.                             No Subscriptions</strong>
  22.                         </EmptyDataTemplate>
  23.                         <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
  24.                         <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
  25.                         <HeaderStyle CssClass="gridheader" Font-Bold="True" ForeColor="Black" Height="20px" />
  26.                         <AlternatingRowStyle BackColor="#EAEAE7" />
  27.                     </asp:GridView>
  28.     </div>
  29.     </form>
  30. </body>
  31. </html>
  32.  
  33.  
this is my c# code
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11.  
  12. public partial class Reguserdetailstest : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         reguserDataGridView.DataSource = null;
  17.         reguserDataGridView.DataBind();
  18.     }
  19.     protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
  20.     {
  21.         reguserDataGridView.PageIndex = e.NewPageIndex;
  22.         reguserDataGridView.DataSource = builddataset();
  23.         reguserDataGridView.DataBind();
  24.     }
  25.  
  26.  
  27.     protected void Button1_Click(object sender, EventArgs e)
  28.     {
  29.       fillgridval();
  30.     }
  31.  
  32.     private void fillgridval()
  33.     {
  34.  
  35.  
  36.  
  37.         BoundField regdateColumn = new BoundField();
  38.         regdateColumn.DataField = "Reg Date";
  39.         regdateColumn.DataFormatString = "{0}";
  40.         regdateColumn.HeaderText = "Reg Date";
  41.  
  42.         BoundField LoginIDColumn = new BoundField();
  43.         LoginIDColumn.DataField = "Login ID";
  44.         LoginIDColumn.DataFormatString = "{0}";
  45.         LoginIDColumn.HeaderText = "Login ID";
  46.  
  47.         BoundField FirstnameColumn = new BoundField();
  48.         FirstnameColumn.DataField = "First Name";
  49.         FirstnameColumn.DataFormatString = "{0}";
  50.         FirstnameColumn.HeaderText = "First Name";
  51.  
  52.         BoundField TokennoColumn = new BoundField();
  53.         TokennoColumn.DataField = "Token No";
  54.         TokennoColumn.DataFormatString = "{0}";
  55.         TokennoColumn.HeaderText = "Token No";
  56.         //crieteriacolumn.HtmlEncode = false;
  57.  
  58.         BoundField RefererColumn = new BoundField();
  59.         RefererColumn.DataField = "Referer";
  60.         RefererColumn.DataFormatString = "{0}";
  61.         RefererColumn.HeaderText = "Referer";
  62.  
  63.  
  64.         BoundField CoursenameColumn = new BoundField();
  65.         CoursenameColumn.DataField = "Course Name";
  66.         CoursenameColumn.DataFormatString = "{0}";
  67.         CoursenameColumn.HeaderText = "Package / Course Name";
  68.         CoursenameColumn.HtmlEncode = false;
  69.  
  70.         reguserDataGridView.Columns.Add(regdateColumn);
  71.         reguserDataGridView.Columns.Add(LoginIDColumn);
  72.         reguserDataGridView.Columns.Add(FirstnameColumn);
  73.         reguserDataGridView.Columns.Add(TokennoColumn);
  74.         reguserDataGridView.Columns.Add(RefererColumn);
  75.         reguserDataGridView.Columns.Add(CoursenameColumn);
  76.  
  77.  
  78.         reguserDataGridView.AutoGenerateColumns = false;
  79.  
  80.         DataSet ds = builddataset();
  81.         reguserDataGridView.DataSource = ds;
  82.         reguserDataGridView.DataBind();
  83.         reguserDataGridView.Visible = true;
  84.     }
  85.  
  86.     private DataSet builddataset()
  87.     {
  88.  
  89.         DataSet ret = new DataSet();
  90.         DataTable dt = new DataTable();
  91.         DataRow dr = null;
  92.  
  93.  
  94.  
  95.         DataColumn dc = new DataColumn("Reg Date", Type.GetType("System.String"));
  96.         dt.Columns.Add(dc);
  97.  
  98.         dc = new DataColumn("Login ID", Type.GetType("System.String"));
  99.         dt.Columns.Add(dc);
  100.  
  101.         dc = new DataColumn("First Name", Type.GetType("System.String"));
  102.         dt.Columns.Add(dc);
  103.  
  104.         dc = new DataColumn("Token No", Type.GetType("System.String"));
  105.         dt.Columns.Add(dc);
  106.  
  107.         dc = new DataColumn("Referer", Type.GetType("System.String"));
  108.         dt.Columns.Add(dc);
  109.  
  110.         dc = new DataColumn("Course Name", Type.GetType("System.String"));
  111.         dt.Columns.Add(dc);
  112.  
  113.  
  114.  
  115.  
  116.             for (int i = 0; i < 100; i++)
  117.             {
  118.  
  119.  
  120.                 dr = dt.NewRow();
  121.                 dr["Reg Date"] = "regdate";
  122.                 dr["Login ID"] = "Login ID";
  123.                 dr["First Name"] = "first Name";
  124.                 dr["Token No"] = "Token No";
  125.                 dr["Referer"] = "Referer";
  126.                 dr["Course Name"] = "Course Name";
  127.  
  128.                 dt.Rows.Add(dr);
  129.             }
  130.  
  131.         ret.Tables.Add(dt);
  132.  
  133.         return ret;
  134.  
  135.  
  136.     }
  137.  
  138.  
  139. }
  140.  
  141.  
when i click first tim in button it is show perfect
when i click next time it is show 2 times
when i click third time it is show 3 times
...............

ex
first time:-

Reg Date Login ID First Name Token No Referer Package / Course Name
regdate Login ID first Name Token No Referer Course Name
regdate Login ID first Name Token No Referer Course Name
regdate Login ID first Name Token No Referer Course Name
regdate Login ID first Name Token No Referer Course Name
regdate Login ID first Name Token No Referer Course Name

second time:-
Reg Date Login ID First Name Token No Referer Package / Course Name Reg Date Login ID First Name Token No Referer Package / Course Name
regdate Login ID first Name Token No Referer Course Name regdate Login ID first Name Token No Referer Course Name
regdate Login ID first Name Token No Referer Course Name regdate Login ID first Name Token No Referer Course Name
regdate Login ID first Name Token No Referer Course Name regdate Login ID first Name Token No Referer Course Name
regdate Login ID first Name Token No Referer Course Name regdate Login ID first Name Token No Referer Course Name
regdate Login ID first Name Token No Referer Course Name regdate Login ID first Name Token No Referer Course Name
regdate Login ID first Name Token No Referer Course Name regdate Login ID first Name Token No Referer Course Name



pls help how can i solve this problem

Thanks
Apr 29 '09 #1
2 1268
balame2004
142 100+
You are adding columns to the grid whenever you populate data into grid control.
You do onething. You delete existing columns before you add columns.

Change your source code to be the following:

protected void Button1_Click(object sender, EventArgs e)
{
reguserDataGridView.Columns.Clear();
fillgridval();
}
Apr 29 '09 #2
yogarajan
115 100+
thanks
it is working fine

Thanks lot
Apr 30 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my...
3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
2
by: Loading name... | last post by:
Hey asp.net 2.0 I have a GridView on my webpage. This GridView's datasource is a SqlDataSource. The SqlDataSource returns 3 columns. Here is my problem: My GridView consist of 3 columns...
3
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a...
2
by: antonyliu2002 | last post by:
I've been googling for some time, and could not find the solution to this problem. I am testing the paging feature of gridview. I have a very simple web form on which the user can select a few...
8
by: =?Utf-8?B?TWlrZSBSYW5k?= | last post by:
I am trying to get a list of files from a specified directory using the System.IO namespace classes, and then use that list as the datasource for a GridView. I have been able to do this...
1
by: Jeff | last post by:
ASP.NET 2.0 I've got problems with the right column in my GridView. The GridView consist of 2 columns, the problem column is the column on the right side. The problem is that it looks like...
2
by: GISmatters | last post by:
I have unbound checkboxes in a nested gridview to allow multi-selection of "child" rows. For context, the parent gridview rows are for large "reports", the child rows are for various specific files...
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...
11
by: Ed Dror | last post by:
Hi there, I'm using ASP.NET 2.0 and SQL Server 2005 with VS 2005 Pro. I have a Price page (my website require login) with GridView with the following columns PriceID, Amount, Approved,...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.