473,545 Members | 2,045 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can't fill Gridview w/ manual columns from dataset/datatable

14 New Member
I am currently filling a dataTable then adding this table to a dataset, setting the dataset to the Gridview's datasource.

If I set the Gridview to generate columns automatically it will fill the grid just fine, but I can't get the automated column (column index 1) to be set to readonly. (Column 0 is actually an automated column of edit buttons)

here's my code:
Expand|Select|Wrap|Line Numbers
  1.         DataSet ds = new DataSet();
  2.         DataTable dt = new DataTable();
  3.         ds.Tables.Add(dt);
  5.         DataColumn dc = new DataColumn("search #");
  6.         dc.ReadOnly = true; 
  8.         dt.Columns.Add(dc);
  9.         dc = new DataColumn("1");
  10.         dt.Columns.Add(dc);
  11.         dc = new DataColumn("2");
  12.         dt.Columns.Add(dc);
  13.         dc = new DataColumn("3");
  14.         dt.Columns.Add(dc);
  15.         dc = new DataColumn("4");
  16.         dt.Columns.Add(dc);
  18.         DataRow dr;
  20.         object[] myArray = new object[maxElements];
  22.         for (int a = 0; a < numSearches; a++)
  23.         {
  24.             for (int b = 0; b < maxElements; b++)
  25.             {
  26.                 myArray[b] = array[a, b];
  27.             }
  28.             dr = dt.NewRow();
  29.             dr.ItemArray = myArray;
  30.             dt.Rows.Add(dr);
  31.         }
  33.         GridView2.DataSource = ds;
  34.         GridView2.DataBind();
notice I do set Column[0] to readonly, but this isn't readonly when binded to the grid, as my edit feature allows for the editing of that column.

Is this an issue with my edit handler/functionality?

Now if I set manual columns in the Gridview, this dataset will not fill those columns when binded to the gridview. Will only bind if I have automated columns set.

ETA: this is an ASP.Net app.

Mar 5 '08 #1
3 7387
7,872 Recognized Expert Expert
After you have set the datasource for your GridView and called the DataBind function, go through and look at the columns or your GridView, you should be able to set them to read only there as well, post process.
Mar 5 '08 #2
14 New Member
do I need to do this in the background code or in the ASP/html area?

I haven't found the path to setting the individual column in the gridview object to read-only.

meaning I can't find any way to get to readonly from:

GridView2.Colum ns....
Mar 5 '08 #3
14 New Member
I found a solution but it's somewhat complex (assuming there's still an easier method).

After DataBind() I do this:

GridView2.DataB ind();

for (int x = 0; x < numSearches; x++)
int x2 = x + 1;

GridView2.Rows[x].Cells[1].Text = x2.ToString();

I added another row manually in the GUI editor so this is the Cells[1] that is being edited and numbers of the searches are being put in manually. This column I set to read only.
Mar 5 '08 #4

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

Similar topics

by: hs | last post by:
Hi I am serializing a dataset using a binary formatter as follows: IFormatter formater = new BinaryFormatter(); formatter.Serialize(stream, ds); // ds=DataSet, stream=MemoryStream .... DataSet ds2 = (DataSet)formatter2.Deserialize(stream2); For the size of my DataSet, its taking 0.8 seconds to serialize and 2.3 seconds to deserialize.
by: Marcin Podle¶ny | last post by:
Hello! I use DataGrid which displays data in several columns. Number of columns depends on user prefferences (I mean: this is still the same query filling datatable but I use "DataTable.Columns(i).ColumnMapping = MappingType.Hidden" to hide columns which should be hidden). So, the code I use every time to fill DataTable and display data in...
by: | last post by:
Hello, I have a GridView in my ASP.NET 2.0 application that performs the paging feature perfect when I have it bound to a data source. But now I have it bound to a dataset and the paging feature will not work. When I try to use paging I get this error: The GridView 'gvResults' fired event PageIndexChanging which wasn't handled.
by: rufpirat | last post by:
Hello I'm in the middle of trying to build an "AD phone book", and this being my first try at asp.net, I have a few questions that I hope some of you might be able to help with: 1. Is it correct, that PageSize equals the max size of the result set? 2. Is there a way to make asp cache the search result, so the domain controller won't be...
by: Richard Carpenter | last post by:
I have a simple winform with a customers combobox, a "get orders" button and an orders grid. Due to other requirements, I have implemented the form to allow the user to select a customer from the combobox and click the "get orders" button to refresh the gridview with the selected customer's orders, via a GetDataByCustomerID stored procedure....
by: mike1402 | last post by:
Hi ! I get the error below sometimes when retrieving a big amount of data using Datadapter.Fill(dataset,"table"). But when I send the command Fill again, there is no error. Is it a fault of IBM.Data.DB2.iSeries; Version: v1.0.3705 (is there an newer one for OS/400 Version ist V5R3 ?) or is it a hardware faoult (memory of as400 or pc) ? br...
by: shapper | last post by:
Hello, I need to loop though each row in a GridView and if the checkbox is a Template Field is checked I want to display the value of an invisible column named "LevelName". I tried everything I could think off but I always get an error or no value. Could someone please let me know what might be wrong?
by: zhshqzyc | last post by:
Hi, I am using the paging skills for my page. I'm doing manual databinding (that is, setting the DataSource property, and then calling DataBind()) instead of automatic databinding. So I manually handle events for paging. But the page is invisible. Thanks for your help. protected void GridView_PageIndexChanging(object sender,...
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one dataset to data in a second dataset, using a common key. I will first describe the problem in words and then I will show my code, which has most of the...
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...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
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...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
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...
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...
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...
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.