Add a column at the end of the Grid

  • Thread starter Christopher Calhoun
  • Start date
C

Christopher Calhoun

Does anyone know how to add a column to the end of a datagrid.

Thanks in Advance.
 
A

Alvin Bruney [MVP]

There are a couple ways to do it. Use your sequel statement to generate a
blank column
select blah, blah as 0.... generates an empty column as the last column.
Alternatively, you can add a column to your column collection or to your
dataview and rebind to display in the grid.
 
R

Richard Ryerson

Does anyone know how to add a column to the end of a datagrid.

Thanks in Advance.

Define either BoundColumn or TemplateColumn for each field / property. They
will appear in the order you define them.

<asp:datagrid id=dgContracts runat="server" AutoGenerateColumns="False"
DataSource="<%# Contracts %>">
<Columns>
<asp:EditCommandColumn CancelText="Cancel" EditText="Edit"
UpdateText="Upate"></asp:EditCommandColumn>
<asp:TemplateColumn HeaderText="Job #">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.Job.JobNumber") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Product">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.Product.Description") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Status">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.Job.Status") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn Text="Select" ButtonType="LinkButton"
ItemStyle-CssClass="submit" CommandName="Select"></asp:ButtonColumn>
</Columns>
</asp:datagrid>
 
C

Christopher Calhoun

How do I determine the last column in a datagrid with auto-generated
columns. I need to use the column.AddAt method to add a button column to the
end of the columns.
In my case this must be done programmatically.
So If I know the last index I can do i that way..


Thanks in Advance!
 
A

Alvin Bruney [MVP]

find the count on the dataset
column.addat(dataset.tables[0].Column.count - 1)
if you have an underlying dataset otherwise use the count returned from the
column collection
 
C

Christopher Calhoun

What event should this be done in? I would think that it should be done
after the column auto generation... in which ever event is fired last...

Hmmmm....

Alvin Bruney said:
find the count on the dataset
column.addat(dataset.tables[0].Column.count - 1)
if you have an underlying dataset otherwise use the count returned from the
column collection

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Christopher Calhoun said:
How do I determine the last column in a datagrid with auto-generated
columns. I need to use the column.AddAt method to add a button column to the
end of the columns.
In my case this must be done programmatically.
So If I know the last index I can do i that way..


Thanks in Advance!
 
A

Alvin Bruney [MVP]

itemdatabound is a good candidate for this. in this case, the last column
would be given by
e.item.cells.count - 1

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Christopher Calhoun said:
What event should this be done in? I would think that it should be done
after the column auto generation... in which ever event is fired last...

Hmmmm....

Alvin Bruney said:
find the count on the dataset
column.addat(dataset.tables[0].Column.count - 1)
if you have an underlying dataset otherwise use the count returned from the
column collection

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Christopher Calhoun said:
How do I determine the last column in a datagrid with auto-generated
columns. I need to use the column.AddAt method to add a button column
to
the
end of the columns.
In my case this must be done programmatically.
So If I know the last index I can do i that way..


Thanks in Advance!

Does anyone know how to add a column to the end of a datagrid.

Thanks in Advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top