473,738 Members | 8,848 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unable to view data in datagrid

16 New Member
the present problem is that i am unable to display data in datagrid....... but the data is visible in database..below is the code what should i do...earlier i could view it also below this code is the code which is in my html page plz help........


Expand|Select|Wrap|Line Numbers
  1. private void Page_Load(object sender, System.EventArgs e)
  2.         {
  3.             if (!Page.IsPostBack)
  4.             {
  5.                 BindData();
  6.             }
  7.  
  8.  
  9.             // Put user code to initialize the page here
  10.             OleDbDataAdapter da = new OleDbDataAdapter("SELECT *FROM CMRS_BUSINESSAREA_MASTER","Provider=MSDAORA.1;User ID=meter_reading;Password=colony;Data Source=windev;OLEDB.NET=true;" );
  11.             DataSet ds = new DataSet();
  12.             da.Fill(ds,"CMRS_BUSINESSAREA_MASTER");
  13.             DataGrid1.DataSource = ds.Tables["CMRS_BUSINESSAREA_MASTER"].DefaultView ;
  14.             DataGrid1.DataBind();
  15.  
  16.         }
  17.  
  18.  
  19.         public void BindData()
  20.         {
  21.             OleDbDataAdapter da = new OleDbDataAdapter("SELECT *FROM CMRS_BUSINESSAREA_MASTER","Provider=MSDAORA.1;User ID=meter_reading;Password=colony;Data Source=windev;OLEDB.NET=true;" ); 
  22.             DataSet ds = new DataSet(); 
  23.             da.Fill(ds);
  24.  
  25.             DataGrid1.DataSource = ds.Tables[0].DefaultView ;
  26.             DataGrid1.DataBind();
  27.  
  28.  
  29.         }
  30.         public void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs   e)
  31.         {
  32.             DataGrid1.EditItemIndex = e.Item.ItemIndex;
  33.             BindData(); 
  34.         }
  35.  
  36.         public void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs   e)
  37.         {
  38.             DataGrid1.EditItemIndex = -1; 
  39.             BindData(); 
  40.         }
  41.  
  42.         public void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs   e)
  43.         {
  44.             string str = ConfigurationSettings.AppSettings["ConnectionString"].ToString();
  45.             OleDbConnection con1 = new OleDbConnection();
  46.             con1.ConnectionString = str;
  47.  
  48.  
  49.             TextBox txtAREADESCRIPTION =(TextBox) e.Item.Cells[1].Controls[0];
  50.             string strUpdateStmt;
  51.  
  52.             strUpdateStmt = "UPDATE CMRS_BUSINESSAREA_MASTER SET " + "CBM_BUSAREA_DESC = '" + txtAREADESCRIPTION.Text + "' " + "WHERE CBM_BUSAREA_CODE ='" + e.Item.Cells[0].Text +"'";
  53.  
  54.             cmd = new OleDbCommand(strUpdateStmt,con1);
  55.             con1.Open();
  56.             cmd.ExecuteNonQuery();         
  57.             DataGrid1.EditItemIndex = -1;
  58.             BindData();
  59.         }
  60.  
  61.  
  62.         #region Web Form Designer generated code
  63.         override protected void OnInit(EventArgs e)
  64.         {
  65.             //
  66.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  67.             //
  68.             InitializeComponent();
  69.             base.OnInit(e);
  70.         }
  71.  
  72.         /// <summary>
  73.         /// Required method for Designer support - do not modify
  74.         /// the contents of this method with the code editor.
  75.         /// </summary>
  76.         private void InitializeComponent()
  77.         {    
  78.             this.cmd = new System.Data.OleDb.OleDbCommand();
  79.             this.con1 = new System.Data.OleDb.OleDbConnection();
  80.             this.addbtn.Click += new System.EventHandler(this.addbtn_Click);
  81.             this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHand  ler(this.DataGrid1_CancelCommand);
  82.             this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHand  ler(this.DataGrid1_EditCommand);
  83.             this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHand  ler(this.DataGrid1_UpdateCommand);
  84.             this.Load += new System.EventHandler(this.Page_Load);
  85.  
  86.         }
  87.         #endregion
  88.  
  89.         private void addbtn_Click(object sender, System.EventArgs e)
  90.         {
  91.             string str = ConfigurationSettings.AppSettings["ConnectionString"].ToString();  
  92.  
  93.             OleDbConnection con1 = new OleDbConnection();
  94.             con1.ConnectionString = str;
  95.             OleDbCommand cmd = new OleDbCommand("Insert into cmrs_businessarea_master values('"+TextBox1.Text+"','"+TextBox2.Text+"')",con1);       
  96.             con1.Open();
  97.             cmd.ExecuteNonQuery();
  98.             con1.Close();
  99.             BindData();
  100.  
  101.  
  102.         }
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.     }
  110.  
  111.  
  112.  
  113. }

Expand|Select|Wrap|Line Numbers
  1. <asp:datagrid id="DataGrid1" style="Z-INDEX: 104; LEFT: 440px; POSITION: absolute; TOP: 304px"
  2.                 runat="server" Height="125px" Width="432px" OnUpdateCommand="DataGrid1_UpdateCommand" OnCancelCommand="DataGrid1_CancelCommand"
  3.                 OnEditCommand="DataGrid1_EditCommand" AutoGenerateColumns="False">
  4.                 <Columns>
  5.                     <asp:BoundColumn HeaderText="AREA CODE"></asp:BoundColumn>
  6.                     <asp:BoundColumn HeaderText="AREA DESCRIPTION"></asp:BoundColumn>
  7.                     <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
  8.                 </Columns>
  9.             </asp:datagrid></form>
Jul 26 '07 #1
0 1399

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

Similar topics

2
1578
by: Chris Mullins | last post by:
I'm building a GUI that needs to be able to view a large amount of text arranged in rows. Large being anywhere from a few hundred lines through a few hundred thousand. I need a way to "cap" the max number of rows, so that old rows are discarded in favor of new rows if the limit is reached. My use case is very similar to that of the SQL Profiler GUI - I'm going to be receiving a large amount of data from a server that I want to display....
3
1650
by: sam | last post by:
Hello group, The datagrid is sorted using a dataview. Can I get the sorted dataview or table from the datagrid or any other way. All I need to get is the sorted data. Here is my code and what I am trying to accomplish: The datagrid is sorted using: dgWIP.DataSource = dvWIP dvWIP.Sort = Me.SortColumn & " " & Me.SortOrder dgWIP.DataBind()
2
5584
by: sunstarwu | last post by:
Hi, I am having difficultly being able to view certain Columns and rows via a DropDownList. Everytime I load my webpage.aspx it just shows empty drop down menus. I have no problem showing all the Excel data in a DataGrid, its just DropDownLists. To view all the data in a DataGrid I just followed the instructions on
3
2189
by: David | last post by:
Hello, I have a datagrid populated with rows from a view. Because they are from a view, the rows are not actual database records, and therefore lack unique identifiers. So I have a command button for each row. When the button is pressed, I want to go to another page with all the information in that selected row. Normally I would do this (if the rows are actual records, that is)
4
4381
by: Souri Challa | last post by:
Hello All, When a datagrid in a web form is getting re populated from view state on post back, it is firing the datagrid Item Created event but the DataGridItem(e.Item.DataItem is null) in the event arguments has no values. Is there any way to access and manipulate the row contents in this case ? Thanks in advance for any insigts in to this. -Souri
6
5516
by: Paolo Pignatelli | last post by:
I have an aspx code behind page that goes something like this in the HTML view: <asp:HyperLink id=HyperLink1 runat="server" NavigateUrl='<%#"mailto:" &amp; DataBinder.Eval(Container.DataItem,"StoreEmail") &amp; "&amp;Subject=" &amp; DataBinder.Eval(Container.DataItem,"ProductName") ....
6
1855
by: Bala | last post by:
Hi all, In my page load i am loading nearly 5 diffferent arrays. each array having nearly 1000 items. after that i am doing some calculation add some list into datagrid using that array values. all the values are maintaing on VIEW STATE. so the page is totaly slow. how to get the array and datagrid values without maintainng the VIEW STATE. any idea? Thanks bala
5
7103
by: ComputerStop | last post by:
I am attempting to print a datagridview. I have not found any method that works successfully. Has any one been successful with this?
1
1186
by: caeserind | last post by:
Hi, I have set the AllowPaging property of datagrid control to be true. But I am still not able to view the page numbers. I have checked that the number of records I am fetching is more thatn the page size limit i have set. Please help me out....
0
8969
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8788
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8210
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6751
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.