Format datagrid columns

A

Alessandro Zifiglio

are you adding a boundColumn at runtime ?
What exactly is the control you are adding at runtime. If its a BoundColumn,
it already exposes various header/item/footer style properties which you can
use for formatting . .look in the BoundColumn Members section
 
T

ton

I add a Buttoncolumn, allthough I rather add a button with a text on it.
This column is bound to the dataset. And for the other columns I add
Boundcolumns, but the do not look good.
Text is wrapped up (several lines) and I cannot set the with of a column.

Do you have any suggestions (and/or additional reading)

Thanks
 
A

Alessandro Zifiglio

boundcolumn1.ItemStyle.Wrap = True
sets wrapping for all item cells of the column
 
T

ton

Perfect !
When the previous button works in the datagrid then this control would be
very usefull.
Next is still possible, but previous canbe pushed after 1 or more next (>),
buto does not change the rows which are displayes and is then disabled
(allthough I pushed several time on next)

Ton
 
A

Alessandro Zifiglio

almost forgot, for the width do :
boundcolumn1.ItemStyle.Width = Unit.Pixel(100)
 
A

Alessandro Zifiglio

This last one is probably a bug in your application. I suggest you try and
run in debug mode again and step through this line by line and see the
execution of your code and what happens as you hit the next or previous
buttons.

The previous button should be able to go all the way to the first page and
then stay disabled if its the first page, and the next button should be able
to go to the last record and then disable on the last. Try and use numbered
links and see if your getting the same behavior whereas to next-previous
links. That is set pager mode to NumericPages whereas to NextPrev.

From your previous posts i've noted that you are doing this correctly and
are also using the OnPageIndexChanged method correctly, so surely you have a
small bug in your code.
 
T

ton

I will do what you suggest.

In the mean time I'm trying to handle the event of the buttoncolumn. I
receive the event, but I want to get the ID of the row:

col = New ButtonColumn '' BoundColumn

col.HeaderText = "ID"

col.DataTextField = "ID"

col.ButtonType = ButtonColumnType.PushButton

col.HeaderStyle.Wrap = False

col.CommandName = "Card"

Datagrid.Columns.Add(col)

AddHandler Datagrid.ItemCommand, AddressOf Me.DataGridCard

----
the datagridcard procedure
Private Sub DataGridCard(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)

Dim datagrid As DataGrid, x As Label

datagrid = CType(sender, DataGrid)

x = FindControl("X")

datagrid.EditItemIndex = e.Item.ItemIndex

x.Text = "Xpage " + CStr(e.CommandName) + " " & e.Item.ItemIndex &
e.CommandArgument ''DataItem

datagrid.DataBind()

End Sub

Since the buttoncolumn displays the recordnumber I want to get that ID. With
that ID i can call my dialog to edit the cardrecord.
How do I get there. The datagrid.edititemindex only modifies the way the
record is shown (an you may edit it), buto that's not what I want to do,
Thanks

Ton
 
T

ton

allthough I have an event firing on:
AddHandler Datagrid.PageIndexChanged, AddressOf Me.nextprev

The debugmode only enters the next buton, when clicking previous, the
NextPrev event is not called ?

Private Sub nextprev(ByVal sender As Object, ByVal e As
DataGridPageChangedEventArgs)

Dim datagrid As DataGrid, x As Label

datagrid = CType(sender, DataGrid)

datagrid.CurrentPageIndex = e.NewPageIndex

datagrid.DataBind()

End Sub
 
A

Alessandro Zifiglio

the onitemcommand is the right place for this. however try Try :
dim MyButton as string
MyButton = CType(e.CommandSource, Button).CommandName


Not sure where you are stuck, are you saying your unable to retrieve what
you stored in the buttons commandName, and commandArugment values or your
not able to get the cell where this button is located
 
T

ton

dim but as Button

but = CType(e.CommandSource, Button) ''.CommandName

x.Text = "Xpage " + but.Text

the but.text gives the text on the button which is the recordid. (Offcourse
I rather do not like to show the recordid, but for now it works.)
Thanx,
Now the prev and it begins to look at a sophisticated control.
 
A

Alessandro Zifiglio

well dont store it in text, store it in commandName, its there for this
purpose. Yeah these little bugs are hard to trace, try the numeric buttons
and see if you still have the same problem.
 
T

ton

this works, but when I push the next button the procedure DataGridCard is
also handled:

So the nextprev button fires (only the next button) via:
AddHandler Datagrid.PageIndexChanged, AddressOf Me.nextprev

but the datagridcard procedure is fired first. Via

AddHandler Datagrid.ItemCommand, AddressOf Me.DataGridCard

Probaly handlers the next also the itemcommand, but why should it come
first?
 
T

ton

this works, but when I push the next button the procedure DataGridCard is
also handled:

So the nextprev button fires (only the next button) via:
AddHandler Datagrid.PageIndexChanged, AddressOf Me.nextprev

but the datagridcard procedure is fired first. Via

AddHandler Datagrid.ItemCommand, AddressOf Me.DataGridCard

Probaly handlers the next also the itemcommand, but why should it come
first?
 
T

ton

but how can i store this property in the commandname, it is a buttoncolumn,
which is databind:
col = New ButtonColumn '' BoundColumn

col.HeaderText = "ID"

col.DataTextField = "ID"

col.ButtonType = ButtonColumnType.PushButton

col.HeaderStyle.Wrap = False

col.CommandName = "Card"

col.ItemStyle.Wrap = False

col.ItemStyle.HorizontalAlign = HorizontalAlign.Center

col.ItemStyle.Width = Unit.Pixel(80)

Datagrid.Columns.Add(col)

AddHandler Datagrid.ItemCommand, AddressOf Me.DataGridCard

My commandname card does not mean anything, but how can I get the
columnvalue of the dataset.
 
A

Alessandro Zifiglio

The buttonColumn has a CommandName property. Set your text value here
instead of the doing it in the buttons text property because this will
display as caption.
 
T

ton

i do not understand what you mean.
in my prev. question I added the source, a few lines below. Can you modify
it ?

Ton
 
T

ton

I think I've solved it. I add the button in unbound mode, add a second
boundcolumn for the ID column, which visible property = False. Via the cell
text property
e.Item.Cells(1).Text I receive the not visible ID



Thanx Alessandro, you helped me very good !!
 
A

Alessandro Zifiglio

yep, using an invisible boundcolumn for the id is widely used and is much
better. Good job ;)
 
T

ton

In the prev/next page I do not get any progressing. I'show the code:
I've changed several properties, such as
allowpaging=true, allow custompaging=true and the vitualpagingcount=100
in the control creation I added 2 button (prev en next) and they where
"redirected" to this procedure:
Private Sub PrevNext(ByVal sender As Object, ByVal e As System.EventArgs)

Dim But As New Button, a As String, b As String

Dim datagrid As DataGrid, x As Label

But = CType(sender, Button)

a = But.CommandName

datagrid = FindControl("GRID" + ClientID)

If But.CommandName = "next" Then

datagrid.CurrentPageIndex = datagrid.CurrentPageIndex + 1

ElseIf But.CommandName = "prev" Then

datagrid.CurrentPageIndex = datagrid.CurrentPageIndex - 1

End If

datagrid.DataBind()

End Sub

Nothing happend, allthough in debug mode I can see that the currentpageindex
is modified
 

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,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top