Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Inserting individual items into a datagrid

Reply
Thread Tools

Inserting individual items into a datagrid

 
 
W Akthar
Guest
Posts: n/a
 
      08-10-2004
Hi,

Is there a way to insert items into a datagrid
individually instead of using datasource and databind??

For example:

I have a collection of people,
I want to be able to iterate through this collection and
insert particular items into a datagrid.

namesCollection = MyService.GetAllNames();
int i=0;
for (i=0;i<namesCollection.Count;i++)
{
Names item = namesCollection[i];
dgNames.Items[i].Cells[0].Text = item.ID.ToString
().TrimEnd();
dgNames.Items[i].Cells[1].Text =
item.Salutation.ToString().TrimEnd();
dgNames.Items[i].Cells[2].Text = item.Initial.
ToString().TrimEnd();
dgNames.Items[i].Cells[3].Text = item.ForeName.
ToString().TrimEnd();
dgNames.Items[i].Cells[4].Text = item.SurName.
ToString().TrimEnd();
}

This falls over because dgNames is out of range!!
Any ideas ???
 
Reply With Quote
 
 
 
 
Bharat Biyani
Guest
Posts: n/a
 
      08-11-2004
Hi,

I dont think u can individually assign values to cells in the grid. However,
what u can do is to set the Autogeneratecolumns property of the datagrid to
false and add itemtemplates to the grid and databind them to the grid. You
can call functions in these item templates which can format the data
according to your requirements.

If u only want to trim data then u can write the code in the Itemdatabound
event of the datagrid.

---
Bharat Biyani ((E-Mail Removed))
http://www.orcim.com


"W Akthar" wrote:

> Hi,
>
> Is there a way to insert items into a datagrid
> individually instead of using datasource and databind??
>
> For example:
>
> I have a collection of people,
> I want to be able to iterate through this collection and
> insert particular items into a datagrid.
>
> namesCollection = MyService.GetAllNames();
> int i=0;
> for (i=0;i<namesCollection.Count;i++)
> {
> Names item = namesCollection[i];
> dgNames.Items[i].Cells[0].Text = item.ID.ToString
> ().TrimEnd();
> dgNames.Items[i].Cells[1].Text =
> item.Salutation.ToString().TrimEnd();
> dgNames.Items[i].Cells[2].Text = item.Initial.
> ToString().TrimEnd();
> dgNames.Items[i].Cells[3].Text = item.ForeName.
> ToString().TrimEnd();
> dgNames.Items[i].Cells[4].Text = item.SurName.
> ToString().TrimEnd();
> }
>
> This falls over because dgNames is out of range!!
> Any ideas ???
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
selecting a variable number of individual items Joe Pizzanley Ruby 3 09-02-2010 08:12 PM
resolve single line with multiple items into mutliple lines, single items ela Perl Misc 12 04-06-2009 06:47 PM
break up a value in a list to a list of individual items r3bol Python 5 11-09-2008 05:44 PM
Taskbar - Past Items back into Current Items Moke Gibboni Computer Support 5 10-29-2008 05:26 PM
A Solution for Rendering Attributes into the Individual Items of a RadioButtonList Dunno ASP .Net Web Controls 0 05-16-2005 03:20 AM



Advertisments