We're working hard on the next version of Developer Fusion. Let us know what you think
we should be up to!
Members
Technology Zones
Articles
Hosted By
Info
|
[4676] Building a Full-Featured Custom DataGrid Control
Last post 10-09-2006 1:32 PM by adwivedi1. 31 replies.
-
-
DMarko1


- Joined on 09-19-2003

- Points 45
|
Setting DataGrid column width at run time
Sure, just add your datagrid column modifications in the ItemCreated event handler.
Ex. in Pixels:
Code:'VB
Private Sub GridCreated (ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles GridCreated
e.Item.Cells(0).Width = New Unit (100, UnitType.Pixel)
e.Item.Cells(1).Width = New Unit (75, UnitType.Pixel)
End Sub
//C#
private void GridCreated (object sender, DataGridItemEventArgs e)
{
e.Item.Cells[0].Width = new Unit (100, UnitType.Pixel);
e.Item.Cells[1].Width = new Unit (75, UnitType.Pixel);
}
Furthermore, you can accomodate other Unit structures such as Percentage.
Ex. in Percentage:
Code:'VB
Private Sub GridCreated (ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles GridCreated
e.Item.Cells(0).Width = New Unit (50, UnitType.Percentage)
e.Item.Cells(1).Width = New Unit (25, UnitType.Percentage)
End Sub
//C#
private void GridCreated (object sender, DataGridItemEventArgs e)
{
e.Item.Cells[0].Width = new Unit (50, UnitType.Percentage);
e.Item.Cells[1].Width = new Unit (25, UnitType.Percentage);
}
Hope this helps.
- Jimmy Markatos
|
|
-
-
-
-
-
-
anabhra


- Joined on 06-02-2005

- Points 25
|
|
-
-
-
DMarko1


- Joined on 09-19-2003

- Points 45
|
Custom DG Ctrl w/Dual Paging, Drag&Drop/Sort Code
Hi all,
I just re-added the forum post containing the new version of my article code. I just thought it easier to repost it again, since I find people requesting this and since the topics become hidden after a while, it won't show up unless you select all topics.
Anyway, here is the link:
Custom DG Ctrl w/ Dual Paging, Drag&Drop/Sort DL code forum post
-Jimmy Markatos
|
|
-
-
-
-
DMarko1


- Joined on 09-19-2003

- Points 45
|
|
-
-
-
-
-
wrocca


- Joined on 12-22-2005

- Points 5
|
Quote:[1]Posted by taxiturner on 3 May 2005 10:25 PM[/1]
LiteralControl lc = (LiteralControl) sender;
DataGridItem container = (DataGridItem) lc.NamingContainer;
lc.Text = ((DataRowView) container.DataItem) [columnName].ToString();
I believe that "container" is your problem.
try:
lc.Text = ((DataRowView)e.Item.DataItem)[columnName].ToString();
Now, if someone could just tell me how to cast a DataGridItemCollection as a TableRowCollection so that I don't get this error, that would be helpful.
|
|
|
Search
Code Samples
New Members
|