473,698 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding data to a Grid View programmaticall y

Hi All,

I'm currently working on a project, and I've come to a part where I
want to add data to a GridView. BUT, I want to do it programmaticall y,
with alot of control over everything. In my particular project I've
passed a DataSet to a page via a Session object. The Session object
passes without incident, and I can use the default settings to retrieve
the information without problem and plug all the information into the
GridView.

However, currently what I'm doing is configuring the .aspx page with
all the appropriate settings (eg. AutoGenerateFie lds=false, define my
columns, etc...) to list only the columns I want using the BoundField
tag. What I'd like to do is do it all programmaticall y in the aspx.cs
file.

So far, my little experiment looks like this:
// Note that grd_SearchResul ts is the GridView control on the .aspx
// page
DataControlFiel d df1 = new BoundField();
df1.HeaderText = "test";
grd_SearchResul ts.Columns.Add( df1);
//grd_SearchResul ts.DataSource = SearchResult;
//grd_SearchResul ts.DataBind();

So far, I can create the column named "test" but the bugger has been
trying to put the data I want into it. Ideally I want to just select
what column from the DataSet to include and go from there.

If there was some kind of control/command where I could type
df1.DataField=" index" or df1.DataField = SearchResult["index"], I think
I'd be all set, but there's no such control/command.

The main reason I want to this is that I can forsee in the future there
will be changes to this project. So the .aspx page is just meant to
represent how I want my data layed out, and the aspx.cs file is meant
to put the data into it. So... in the future, I (or someone else)
will be able to just mess with the code-behind only. Basically, for
ease of maintenance.

I'm sure there's a way of doing it. It could be I'll have to dig into
things a bit more and make things more complicated too. But, oh well,
guess that's just part of learning :)

Thanks for any input in advance,
Wayne D.

Dec 21 '06 #1
2 6728
Hi Wayne

Try changing:

DataControlFiel d df1 = new BoundField(); to
BoundField df1 = new BoundField();

You'll then have access to the BoundField's DataField property.

HTH
Mark

Wayne Deleer wrote:
Hi All,

I'm currently working on a project, and I've come to a part where I
want to add data to a GridView. BUT, I want to do it programmaticall y,
with alot of control over everything. In my particular project I've
passed a DataSet to a page via a Session object. The Session object
passes without incident, and I can use the default settings to retrieve
the information without problem and plug all the information into the
GridView.

However, currently what I'm doing is configuring the .aspx page with
all the appropriate settings (eg. AutoGenerateFie lds=false, define my
columns, etc...) to list only the columns I want using the BoundField
tag. What I'd like to do is do it all programmaticall y in the aspx.cs
file.

So far, my little experiment looks like this:
// Note that grd_SearchResul ts is the GridView control on the .aspx
// page
DataControlFiel d df1 = new BoundField();
df1.HeaderText = "test";
grd_SearchResul ts.Columns.Add( df1);
//grd_SearchResul ts.DataSource = SearchResult;
//grd_SearchResul ts.DataBind();

So far, I can create the column named "test" but the bugger has been
trying to put the data I want into it. Ideally I want to just select
what column from the DataSet to include and go from there.

If there was some kind of control/command where I could type
df1.DataField=" index" or df1.DataField = SearchResult["index"], I think
I'd be all set, but there's no such control/command.

The main reason I want to this is that I can forsee in the future there
will be changes to this project. So the .aspx page is just meant to
represent how I want my data layed out, and the aspx.cs file is meant
to put the data into it. So... in the future, I (or someone else)
will be able to just mess with the code-behind only. Basically, for
ease of maintenance.

I'm sure there's a way of doing it. It could be I'll have to dig into
things a bit more and make things more complicated too. But, oh well,
guess that's just part of learning :)

Thanks for any input in advance,
Wayne D.
Dec 22 '06 #2
Sweet, thanks dunny.
dunny wrote:
Hi Wayne

Try changing:

DataControlFiel d df1 = new BoundField(); to
BoundField df1 = new BoundField();

You'll then have access to the BoundField's DataField property.

HTH
Mark

Wayne Deleer wrote:
Hi All,

I'm currently working on a project, and I've come to a part where I
want to add data to a GridView. BUT, I want to do it programmaticall y,
with alot of control over everything. In my particular project I've
passed a DataSet to a page via a Session object. The Session object
passes without incident, and I can use the default settings to retrieve
the information without problem and plug all the information into the
GridView.

However, currently what I'm doing is configuring the .aspx page with
all the appropriate settings (eg. AutoGenerateFie lds=false, define my
columns, etc...) to list only the columns I want using the BoundField
tag. What I'd like to do is do it all programmaticall y in the aspx.cs
file.

So far, my little experiment looks like this:
// Note that grd_SearchResul ts is the GridView control on the .aspx
// page
DataControlFiel d df1 = new BoundField();
df1.HeaderText = "test";
grd_SearchResul ts.Columns.Add( df1);
//grd_SearchResul ts.DataSource = SearchResult;
//grd_SearchResul ts.DataBind();

So far, I can create the column named "test" but the bugger has been
trying to put the data I want into it. Ideally I want to just select
what column from the DataSet to include and go from there.

If there was some kind of control/command where I could type
df1.DataField=" index" or df1.DataField = SearchResult["index"], I think
I'd be all set, but there's no such control/command.

The main reason I want to this is that I can forsee in the future there
will be changes to this project. So the .aspx page is just meant to
represent how I want my data layed out, and the aspx.cs file is meant
to put the data into it. So... in the future, I (or someone else)
will be able to just mess with the code-behind only. Basically, for
ease of maintenance.

I'm sure there's a way of doing it. It could be I'll have to dig into
things a bit more and make things more complicated too. But, oh well,
guess that's just part of learning :)

Thanks for any input in advance,
Wayne D.
Dec 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2497
by: pmud | last post by:
Hi, I need to display columns in a data grid based on 7 different queries. Now I have 32 questions: 1. Is it possble to have 1 single data adapter with 7 queries & 1 data set or do I need to have a separate data adapter & a separate data set for each select query? If thats possible then how?
3
4878
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
3
2739
by: Simon Harris | last post by:
Hi All, I have a data grid which displays country names. I now wish to display the country flag images above the names. Can someone please advise how I display an image in a datagrid? I have a folder of flag images, named in relations to the countries database ID. Current data grid code is...
10
1931
by: John Wilson | last post by:
My app produces some long datatables to display in a grid. So I put them in a div so users can scroll. But the grid headers scroll out of view. I would like to stop them doing this. Can I fix them in place at the top of the div? -- John Wilson
7
14806
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1 but how is this done now in asp.net 2.0?
2
2029
by: bob | last post by:
After adding a new row (programmatically) to a table/view that is being displayed in the DataGridView control, the new row appears in the DataGridView grid. Now, how do I select that new row? If the DataGridView is sorted by one of the columns/fields, the new row could show up anywhere (based on the sort criteria). Thanks.
2
4707
by: moondaddy | last post by:
I'm trying to do something real simple. Add a thumb to a grid at the end of a line using c#. the code executes but I dont see the thumb. Can anyone explain what and what I need to do to properly show the thumb? Here's the xaml for the window and the c# below. <Window x:Class="DragLineSample.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
0
1692
by: db007 | last post by:
I have a problem at the moment with a web project. I have two Panels within an UpdatePanel on an aspx page (using Masterpages). I'm using ASP.Net 2.0 with an AJAX enabled website. The two Panels represent a Master-Detail type relationship. I want a user to click a LinkButton in the first Panel and then for the 2nd Panel to be displayed with the detail. However, I need to set some text properties of textboxes programmatically when the...
6
2942
by: insirawali | last post by:
Hi all, I have this problem, i need to know is there a way i cn use the data adapter's update method in this scenario. i have 3 tables as below create table table1{ id1 int identity(1,1) Constraint pk_table1 Primary Key,
0
8678
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
8609
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
9166
Oralloy
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9030
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
8899
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
8871
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...
1
6525
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
5861
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
4621
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.