473,795 Members | 2,443 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);
  4.  
  5.         DataColumn dc = new DataColumn("search #");
  6.         dc.ReadOnly = true; 
  7.  
  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);
  17.  
  18.         DataRow dr;
  19.  
  20.         object[] myArray = new object[maxElements];
  21.  
  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.         }
  32.  
  33.         GridView2.DataSource = ds;
  34.         GridView2.DataBind();
  35.  
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.

thanks.
Mar 5 '08 #1
3 7406
Plater
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
ASPnewb1
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
ASPnewb1
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

4
8712
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.
0
1198
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 DataGrid looks like: Private Sub xxxxx(...) Dim firstTime as Boolean = true
2
16346
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.
2
4460
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 to bother by all the lookups, and also to speed up
3
1979
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. The underlying Orders table includes, among others, three boolean columns and one particular...
0
4561
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 mike Es wurde versucht, im geschützten Speicher zu lesen oder zu schreiben. Dies ist häufig ein...
3
4077
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?
4
2990
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, GridViewPageEventArgs e) { DataSet myDataSet = new DataSet(); ...
3
2845
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 solution done already. I have built an ASP.NET that queries an Index Server and returns a...
0
9672
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
9519
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
10214
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...
1
10164
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9042
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...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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

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.