Showing posts with label column. Show all posts
Showing posts with label column. Show all posts

Saturday, March 31, 2012

Triggering ItemCommand with ImageButton in Datagrid

Hi

I had a Delete Column in a datagrid that was a Linkbutton. That needed to
change into a ImageButton because of the design demands in the project. Then
how do I trigger the DeleteCommand with that button?

I don't want to have to add a AddHandler in the ItemCreated or ItemDataBound
for this ImageButton cause then I can't get the ID from the Row to delete as
easy...

please help/
Lars NetzelSpecify the ImageButton with CommandName="Delete" attribute.

<asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" .../
CommandNames Cancel, Delete, Edit, NextPage, Page, PrevPage, Select, Sort
and Update correspond to the same action with the DataGrid (DataGrid has
these command names predefined for cthese actions)

See docs for further details.

--
Teemu Keiski
ASP.NET MVP, Finland

"Lars Netzel" <uihsdf@.adf.se> wrote in message
news:%23edWRq6LFHA.3328@.TK2MSFTNGP14.phx.gbl...
> Hi
> I had a Delete Column in a datagrid that was a Linkbutton. That needed to
> change into a ImageButton because of the design demands in the project.
> Then how do I trigger the DeleteCommand with that button?
> I don't want to have to add a AddHandler in the ItemCreated or
> ItemDataBound for this ImageButton cause then I can't get the ID from the
> Row to delete as easy...
> please help/
> Lars Netzel
Ah, stupid me:) I wrote ItemCommand instead of CommandName... thx

/Lars

"Teemu Keiski" <joteke@.aspalliance.com> wrote in message
news:eHCfx26LFHA.3988@.tk2msftngp13.phx.gbl...
> Specify the ImageButton with CommandName="Delete" attribute.
> <asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" .../>
> CommandNames Cancel, Delete, Edit, NextPage, Page, PrevPage, Select, Sort
> and Update correspond to the same action with the DataGrid (DataGrid has
> these command names predefined for cthese actions)
> See docs for further details.
> --
> Teemu Keiski
> ASP.NET MVP, Finland
> "Lars Netzel" <uihsdf@.adf.se> wrote in message
> news:%23edWRq6LFHA.3328@.TK2MSFTNGP14.phx.gbl...
>> Hi
>>
>> I had a Delete Column in a datagrid that was a Linkbutton. That needed to
>> change into a ImageButton because of the design demands in the project.
>> Then how do I trigger the DeleteCommand with that button?
>>
>> I don't want to have to add a AddHandler in the ItemCreated or
>> ItemDataBound for this ImageButton cause then I can't get the ID from the
>> Row to delete as easy...
>>
>> please help/
>> Lars Netzel
>>

Triggering ItemCommand with ImageButton in Datagrid

Hi
I had a Delete Column in a datagrid that was a Linkbutton. That needed to
change into a ImageButton because of the design demands in the project. Then
how do I trigger the DeleteCommand with that button?
I don't want to have to add a AddHandler in the ItemCreated or ItemDataBound
for this ImageButton cause then I can't get the ID from the Row to delete as
easy...
please help/
Lars NetzelSpecify the ImageButton with CommandName="Delete" attribute.
<asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" .../>
CommandNames Cancel, Delete, Edit, NextPage, Page, PrevPage, Select, Sort
and Update correspond to the same action with the DataGrid (DataGrid has
these command names predefined for cthese actions)
See docs for further details.
Teemu Keiski
ASP.NET MVP, Finland
"Lars Netzel" <uihsdf@.adf.se> wrote in message
news:%23edWRq6LFHA.3328@.TK2MSFTNGP14.phx.gbl...
> Hi
> I had a Delete Column in a datagrid that was a Linkbutton. That needed to
> change into a ImageButton because of the design demands in the project.
> Then how do I trigger the DeleteCommand with that button?
> I don't want to have to add a AddHandler in the ItemCreated or
> ItemDataBound for this ImageButton cause then I can't get the ID from the
> Row to delete as easy...
> please help/
> Lars Netzel
>
Ah, stupid me:) I wrote ItemCommand instead of CommandName... thx
/Lars
"Teemu Keiski" <joteke@.aspalliance.com> wrote in message
news:eHCfx26LFHA.3988@.tk2msftngp13.phx.gbl...
> Specify the ImageButton with CommandName="Delete" attribute.
> <asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" .../>
> CommandNames Cancel, Delete, Edit, NextPage, Page, PrevPage, Select, Sort
> and Update correspond to the same action with the DataGrid (DataGrid has
> these command names predefined for cthese actions)
> See docs for further details.
> --
> Teemu Keiski
> ASP.NET MVP, Finland
> "Lars Netzel" <uihsdf@.adf.se> wrote in message
> news:%23edWRq6LFHA.3328@.TK2MSFTNGP14.phx.gbl...
>

Trim string to fit in fixed width Table Cell [Edited by Adec, moderator]

I have the following BIG problemSmile [:)]
The column of datagrid is bind to a database field.
If lenght of string is bigger than the column width i want to trim the string.
No metter if the trimmed word has sense.
I would like to know if anyone knows if there is a way to calculate
string width in pixel in connection to font size used in that particular cell.
You can check the string size and do what you need to with it in your DataGridItemCreated event handler.
that's ok for the position where check, but the problem is how measure the width in pixel of the string:-)
Your getting confused, and making this to complicated. You dont measure strings in pixels, you measure strings in Charatchers, figure out how many charatchers will fit in the column of your datagrid, and trim the string to that amount of chars, I would recomend trimming it to 3 less chars than will fit and appending on a ... so that users know it's been trimmed.
Remember, capital letters take up more space than lower case ones, and different ascii chars can take up a space and a half in some cases purley literally speaking, like the @. symbol.

I would suggest you use sql to get the substring - select substring(myfield, 1, 10) as myfield from my table. This gets the first 10 characters. To add the "..." then select substring(myfield, 1, 7)+'...' as myfield from my table


It is ok, i will follow your indication. But still look for a method like TextWidth("...") to use in application.
Thanks. Best Regards

Wednesday, March 28, 2012

Trimming text returned from db

Hi

In my App I have a datagrid with a template column. In my DB I have a field called "Bio" wich holds user biographies. The idea is that within the datagrid only a small portion of the bio is shown and visitors click onto detail pages to see photgraphs and full information. Is there a way to limit the output from the Bio field to say 100 characters

Thanks

hpYou could limit the size of what you display in your datagrid column for Bio through many ways. One of those is to limit what you fetch from the database using LEFT(Bio,100) in your SQL statement.

You could equally use a bound column. This is what MSDN has to say on that:

"A bound column (BoundColumn element) displays information from one column of a data source. You typically add one bound column to the grid for every data column you want to display. Use bound columns when you want to choose which data columns to display in the grid. Bound columns also allow you to set a variety of properties to specify features such as:

The text, font, and color of the column header and footer.
Column width.
Data format.

Whether the column is read-only (that is, whether it will display an editable control when the row is in edit mode).
For details on creating bound columns in the Visual Studio Web Forms Designer, see Adding Bound Columns to a DataGrid Web Server Control. For details on creating bound columns, see DataGrid Web Server Control."

You should be able to combine both approaches to evolve something nice.
In addition if you need the full bio from the db to use later one (perhaps they can vie the full bio via a link or something), you may want to just limit it on the front end. To do this you could use the ItemDataBound of the datagrid. If the value is stored in a control such as a lable you would use FindControl and then set the value. Something like this...

Label lblTemp = (Label)e.Item.FindControl("lblBio");
if (lblTemp != null)
lblTemp = lblTemp.Text.Substring(1, 100);

May not be completely accurate but it should get you on the right path.
Excellent, Many thanks

trimming text in a datagrid to match column length

I have a messaging application that has a data grid with information like an
email list would have (from, subject, time sent, size) but the subject
could be very long in theory, and then it would word wrap.. the subject is a
variable width column (resizes to fit space) while the others are fixed
size... the problem is that i dont want the text to ever word wrap.. but
truncate the visible subject to match the current cell width... (kinda like
gmail does) how would i go about doing this at runtime on the client's page?
thanks!I guess there are a couple of ways that I can think of to fix this. The fir
st and easiest way could be to only return a certain number of characters fr
om the query of stored procedure. For example:
select substring(subject, 0, 10) from emaillist
that way the query will do all the work.
Now another example could be to do it within the code, for example:
<ItemTemplate>
<%# TrimSubject(DataBinder.Eval(Container.DataItem, "Subject")) %>
</ItemTemplate>
public string TrimSubject(string subject)
{
string retVal = subject;
if(retVal.Length>100)
{
retVal = retVal.Substring(0, 100) + "...";
}
return retVal;
}
Hope those examples help.
Alan Washington
http://www.aewnet.com

> I have a messaging application that has a data grid with information like
an
> email list would have (from, subject, time sent, size) but the subject
> could be very long in theory, and then it would word wrap.. the subject is
a
> variable width column (resizes to fit space) while the others are fixed
> size... the problem is that i dont want the text to ever word wrap.. but
> truncate the visible subject to match the current cell width... (kinda lik
e
> gmail does) how would i go about doing this at runtime on the client's pag
e?
> thanks!
>
>
User submitted from AEWNET (http://www.aewnet.com/)
You can use GDI+ to do this. Here's some quick/dirty code I wrote to do
this. Hope this helps!
Joel Cade, MCSD
Fig Tree Solutions, LLC
http://www.figtreesolutions.com
Imports System.Drawing
Public Function MeasureString(ByVal Value As String, ByVal Font As
Drawing.Font) As SizeF
' Set up string.
Dim oBitMap As New Bitmap(1, 1)
Dim oGraphics As Graphics = Graphics.FromImage(oBitMap)
' Measure string.
Dim Size As New SizeF
Size = oGraphics.MeasureString(Value, Font)
Return Size
End Function
Public Function GetTrimmedString(ByVal Value As String, ByVal MaxSizeF
As Single, ByVal Font As Drawing.Font) As String
Dim sReturn As String
If MeasureString(Value, Font).Width < MaxSizeF Then
sReturn = Value
Else
sReturn = Value
Dim i As Integer
Do While MeasureString(Value.Substring(0, Value.Length - i) &
"...", Font).Width > MaxSizeF
i += 1
Loop
sReturn = Value.Substring(0, Value.Length - i) & "..."
End If
Return sReturn
End Function
....
ListBox1.Items.Add(oFormatter.GetTrimmedString("This is a test, THIS IS THE
LONGEST EVER THIS IS THE LONGEST EVER THIS IS THE LONGEST EVER THIS IS THE
LONGEST EVER", 300, New Font(New
System.Drawing.FontFamily(ListBox1.Font.Name), 12, FontStyle.Regular)))
GDI+ on asp.net on the client side? doesn't sound right, because the user
could resize the window thus changing the size of the column the text is in.
"Joel Cade" <joel@.nospam.figtreesolutions.com> wrote in message
news:0F697488-C620-4C51-80EB-803D11AF5D0C@.microsoft.com...
> You can use GDI+ to do this. Here's some quick/dirty code I wrote to do
> this. Hope this helps!
> Joel Cade, MCSD
> Fig Tree Solutions, LLC
> http://www.figtreesolutions.com
> Imports System.Drawing
> Public Function MeasureString(ByVal Value As String, ByVal Font As
> Drawing.Font) As SizeF
> ' Set up string.
> Dim oBitMap As New Bitmap(1, 1)
> Dim oGraphics As Graphics = Graphics.FromImage(oBitMap)
> ' Measure string.
> Dim Size As New SizeF
> Size = oGraphics.MeasureString(Value, Font)
> Return Size
> End Function
> Public Function GetTrimmedString(ByVal Value As String, ByVal MaxSizeF
> As Single, ByVal Font As Drawing.Font) As String
> Dim sReturn As String
> If MeasureString(Value, Font).Width < MaxSizeF Then
> sReturn = Value
> Else
> sReturn = Value
> Dim i As Integer
> Do While MeasureString(Value.Substring(0, Value.Length - i) &
> "...", Font).Width > MaxSizeF
> i += 1
> Loop
> sReturn = Value.Substring(0, Value.Length - i) & "..."
> End If
> Return sReturn
> End Function
> ....
> ListBox1.Items.Add(oFormatter.GetTrimmedString("This is a test, THIS IS
> THE
> LONGEST EVER THIS IS THE LONGEST EVER THIS IS THE LONGEST EVER THIS IS THE
> LONGEST EVER", 300, New Font(New
> System.Drawing.FontFamily(ListBox1.Font.Name), 12, FontStyle.Regular)))
>
Hi Brian,
As for the truncating string values in DataGrid Cell(Table cell), I think
generally we have two means:
1. Truncating the string's length at serverside when we retrieve it from db
or output into the page via code. Just as the other members have suggested.
But this will make the output string's length be a fixed size.
#Creating a Custom DataGridColumn Class, Part 2
http://aspnet.4guysfromrolla.com/ar...100202-1.2.aspx
2. Using css style on the output <table> and the text content in table
cell. There is one css attribute named
"OVERFLOW", it can be applied on <div> or <p> ... and when we set the
"OVERFLOW:Hidden", it will truncat the exceeded content according to the
container element's width.
#overflow Attribute | overflow Property
http://msdn.microsoft.com/library/d...uthor/dhtml/ref
erence/properties/overflow.asp
For example:
<p style="OVERFLOW:hidden;WIDTH:100">
<% Response.Write(new String('d',1000)); %>
</p>
Also, since in our problem, we need to set the datagrid column's width
unfixed, so we also need to make the with of the <p> as a relative size.
After some testing, it seems that we also have to assign the "table-layout
: fixed" css attribute to the DataGrid(<table> ). Here is some demo code on
applying the styles on datagrid:
<asp:DataGrid id="dgStyle" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="Column1"
HeaderText="Column1"></asp:BoundColumn>
<asp:BoundColumn DataField="Column2"
HeaderText="Column2"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Column3">
<ItemTemplate>
<p style="OVERFLOW:hidden;WIDTH:90%">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.Column3") %>'>
</p>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
=======================
In our code-behind , we can use the following code (in Page_load) to apply
the "table-layout" style on datagrid:
private void Page_Load(object sender, System.EventArgs e)
{
...............
dgStyle.Style["TABLE-LAYOUT"] = "fixed";
}
Hope these help. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
thanks that worked perfectly!
"Steven Cheng[MSFT]" <v-schang@.online.microsoft.com> wrote in message
news:%23bjDCLxtEHA.3696@.cpmsftngxa10.phx.gbl...
> Hi Brian,
> As for the truncating string values in DataGrid Cell(Table cell), I think
> generally we have two means:
> 1. Truncating the string's length at serverside when we retrieve it from
> db
> or output into the page via code. Just as the other members have
> suggested.
> But this will make the output string's length be a fixed size.
> #Creating a Custom DataGridColumn Class, Part 2
> http://aspnet.4guysfromrolla.com/ar...100202-1.2.aspx
> 2. Using css style on the output <table> and the text content in table
> cell. There is one css attribute named
> "OVERFLOW", it can be applied on <div> or <p> ... and when we set the
> "OVERFLOW:Hidden", it will truncat the exceeded content according to the
> container element's width.
> #overflow Attribute | overflow Property
> [url]http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/ref[/ur
l]
> erence/properties/overflow.asp
> For example:
> <p style="OVERFLOW:hidden;WIDTH:100">
> <% Response.Write(new String('d',1000)); %>
> </p>
> Also, since in our problem, we need to set the datagrid column's width
> unfixed, so we also need to make the with of the <p> as a relative size.
> After some testing, it seems that we also have to assign the "table-layout
> : fixed" css attribute to the DataGrid(<table> ). Here is some demo code
> on
> applying the styles on datagrid:
> <asp:DataGrid id="dgStyle" runat="server" AutoGenerateColumns="False">
> <Columns>
> <asp:BoundColumn DataField="Column1"
> HeaderText="Column1"></asp:BoundColumn>
> <asp:BoundColumn DataField="Column2"
> HeaderText="Column2"></asp:BoundColumn>
> <asp:TemplateColumn HeaderText="Column3">
> <ItemTemplate>
> <p style="OVERFLOW:hidden;WIDTH:90%">
> <asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
> "DataItem.Column3") %>'>
> </p>
> </asp:Label>
> </ItemTemplate>
> </asp:TemplateColumn>
> </Columns>
> </asp:DataGrid>
> =======================
> In our code-behind , we can use the following code (in Page_load) to apply
> the "table-layout" style on datagrid:
> private void Page_Load(object sender, System.EventArgs e)
> {
> ...............
> dgStyle.Style["TABLE-LAYOUT"] = "fixed";
> }
>
> Hope these help. Thanks.
> Regards,
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>

trimming text in a datagrid to match column length

I have a messaging application that has a data grid with information like an
email list would have (from, subject, time sent, size) but the subject
could be very long in theory, and then it would word wrap.. the subject is a
variable width column (resizes to fit space) while the others are fixed
size... the problem is that i dont want the text to ever word wrap.. but
truncate the visible subject to match the current cell width... (kinda like
gmail does) how would i go about doing this at runtime on the client's page?
thanks!I guess there are a couple of ways that I can think of to fix this. The first and easiest way could be to only return a certain number of characters from the query of stored procedure. For example:

select substring(subject, 0, 10) from emaillist

that way the query will do all the work.

Now another example could be to do it within the code, for example:

<ItemTemplate>
<%# TrimSubject(DataBinder.Eval(Container.DataItem, "Subject")) %>
</ItemTemplate
public string TrimSubject(string subject)
{
string retVal = subject;
if(retVal.Length>100)
{
retVal = retVal.Substring(0, 100) + "...";
}

return retVal;
}

Hope those examples help.

Alan Washington
http://www.aewnet.com

> I have a messaging application that has a data grid with information like an
> email list would have (from, subject, time sent, size) but the subject
> could be very long in theory, and then it would word wrap.. the subject is a
> variable width column (resizes to fit space) while the others are fixed
> size... the problem is that i dont want the text to ever word wrap.. but
> truncate the visible subject to match the current cell width... (kinda like
> gmail does) how would i go about doing this at runtime on the client's page?
> thanks!

User submitted from AEWNET (http://www.aewnet.com/)
You can use GDI+ to do this. Here's some quick/dirty code I wrote to do
this. Hope this helps!

Joel Cade, MCSD
Fig Tree Solutions, LLC
http://www.figtreesolutions.com

Imports System.Drawing

Public Function MeasureString(ByVal Value As String, ByVal Font As
Drawing.Font) As SizeF
' Set up string.
Dim oBitMap As New Bitmap(1, 1)
Dim oGraphics As Graphics = Graphics.FromImage(oBitMap)

' Measure string.
Dim Size As New SizeF
Size = oGraphics.MeasureString(Value, Font)

Return Size
End Function

Public Function GetTrimmedString(ByVal Value As String, ByVal MaxSizeF
As Single, ByVal Font As Drawing.Font) As String
Dim sReturn As String

If MeasureString(Value, Font).Width < MaxSizeF Then
sReturn = Value
Else
sReturn = Value

Dim i As Integer

Do While MeasureString(Value.Substring(0, Value.Length - i) &
"...", Font).Width > MaxSizeF
i += 1
Loop

sReturn = Value.Substring(0, Value.Length - i) & "..."
End If

Return sReturn
End Function

.....

ListBox1.Items.Add(oFormatter.GetTrimmedString("This is a test, THIS IS THE
LONGEST EVER THIS IS THE LONGEST EVER THIS IS THE LONGEST EVER THIS IS THE
LONGEST EVER", 300, New Font(New
System.Drawing.FontFamily(ListBox1.Font.Name), 12, FontStyle.Regular)))
GDI+ on asp.net on the client side? doesn't sound right, because the user
could resize the window thus changing the size of the column the text is in.

"Joel Cade" <joel@.nospam.figtreesolutions.com> wrote in message
news:0F697488-C620-4C51-80EB-803D11AF5D0C@.microsoft.com...
> You can use GDI+ to do this. Here's some quick/dirty code I wrote to do
> this. Hope this helps!
> Joel Cade, MCSD
> Fig Tree Solutions, LLC
> http://www.figtreesolutions.com
> Imports System.Drawing
> Public Function MeasureString(ByVal Value As String, ByVal Font As
> Drawing.Font) As SizeF
> ' Set up string.
> Dim oBitMap As New Bitmap(1, 1)
> Dim oGraphics As Graphics = Graphics.FromImage(oBitMap)
> ' Measure string.
> Dim Size As New SizeF
> Size = oGraphics.MeasureString(Value, Font)
> Return Size
> End Function
> Public Function GetTrimmedString(ByVal Value As String, ByVal MaxSizeF
> As Single, ByVal Font As Drawing.Font) As String
> Dim sReturn As String
> If MeasureString(Value, Font).Width < MaxSizeF Then
> sReturn = Value
> Else
> sReturn = Value
> Dim i As Integer
> Do While MeasureString(Value.Substring(0, Value.Length - i) &
> "...", Font).Width > MaxSizeF
> i += 1
> Loop
> sReturn = Value.Substring(0, Value.Length - i) & "..."
> End If
> Return sReturn
> End Function
> ....
> ListBox1.Items.Add(oFormatter.GetTrimmedString("This is a test, THIS IS
> THE
> LONGEST EVER THIS IS THE LONGEST EVER THIS IS THE LONGEST EVER THIS IS THE
> LONGEST EVER", 300, New Font(New
> System.Drawing.FontFamily(ListBox1.Font.Name), 12, FontStyle.Regular)))
Hi Brian,

As for the truncating string values in DataGrid Cell(Table cell), I think
generally we have two means:

1. Truncating the string's length at serverside when we retrieve it from db
or output into the page via code. Just as the other members have suggested.
But this will make the output string's length be a fixed size.

#Creating a Custom DataGridColumn Class, Part 2
http://aspnet.4guysfromrolla.com/ar...100202-1.2.aspx

2. Using css style on the output <table> and the text content in table
cell. There is one css attribute named
"OVERFLOW", it can be applied on <div> or <p> ... and when we set the
"OVERFLOW:Hidden", it will truncat the exceeded content according to the
container element's width.

#overflow Attribute | overflow Property
http://msdn.microsoft.com/library/d...uthor/dhtml/ref
erence/properties/overflow.asp

For example:

<p style="OVERFLOW:hidden;WIDTH:100">
<% Response.Write(new String('d',1000)); %>
</p
Also, since in our problem, we need to set the datagrid column's width
unfixed, so we also need to make the with of the <p> as a relative size.
After some testing, it seems that we also have to assign the "table-layout
: fixed" css attribute to the DataGrid(<table>). Here is some demo code on
applying the styles on datagrid:

<asp:DataGrid id="dgStyle" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="Column1"
HeaderText="Column1"></asp:BoundColumn>
<asp:BoundColumn DataField="Column2"
HeaderText="Column2"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Column3">
<ItemTemplate>
<p style="OVERFLOW:hidden;WIDTH:90%">
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
"DataItem.Column3") %>'>
</p>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid
=======================
In our code-behind , we can use the following code (in Page_load) to apply
the "table-layout" style on datagrid:

private void Page_Load(object sender, System.EventArgs e)
{
...............

dgStyle.Style["TABLE-LAYOUT"] = "fixed";
}

Hope these help. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
thanks that worked perfectly!

"Steven Cheng[MSFT]" <v-schang@.online.microsoft.com> wrote in message
news:%23bjDCLxtEHA.3696@.cpmsftngxa10.phx.gbl...
> Hi Brian,
> As for the truncating string values in DataGrid Cell(Table cell), I think
> generally we have two means:
> 1. Truncating the string's length at serverside when we retrieve it from
> db
> or output into the page via code. Just as the other members have
> suggested.
> But this will make the output string's length be a fixed size.
> #Creating a Custom DataGridColumn Class, Part 2
> http://aspnet.4guysfromrolla.com/ar...100202-1.2.aspx
> 2. Using css style on the output <table> and the text content in table
> cell. There is one css attribute named
> "OVERFLOW", it can be applied on <div> or <p> ... and when we set the
> "OVERFLOW:Hidden", it will truncat the exceeded content according to the
> container element's width.
> #overflow Attribute | overflow Property
> http://msdn.microsoft.com/library/d...uthor/dhtml/ref
> erence/properties/overflow.asp
> For example:
> <p style="OVERFLOW:hidden;WIDTH:100">
> <% Response.Write(new String('d',1000)); %>
> </p>
> Also, since in our problem, we need to set the datagrid column's width
> unfixed, so we also need to make the with of the <p> as a relative size.
> After some testing, it seems that we also have to assign the "table-layout
> : fixed" css attribute to the DataGrid(<table>). Here is some demo code
> on
> applying the styles on datagrid:
> <asp:DataGrid id="dgStyle" runat="server" AutoGenerateColumns="False">
> <Columns>
> <asp:BoundColumn DataField="Column1"
> HeaderText="Column1"></asp:BoundColumn>
> <asp:BoundColumn DataField="Column2"
> HeaderText="Column2"></asp:BoundColumn>
> <asp:TemplateColumn HeaderText="Column3">
> <ItemTemplate>
> <p style="OVERFLOW:hidden;WIDTH:90%">
> <asp:Label runat="server" Text='<%# DataBinder.Eval(Container,
> "DataItem.Column3") %>'>
> </p>
> </asp:Label>
> </ItemTemplate>
> </asp:TemplateColumn>
> </Columns>
> </asp:DataGrid>
> =======================
> In our code-behind , we can use the following code (in Page_load) to apply
> the "table-layout" style on datagrid:
> private void Page_Load(object sender, System.EventArgs e)
> {
> ...............
> dgStyle.Style["TABLE-LAYOUT"] = "fixed";
> }
>
> Hope these help. Thanks.
> Regards,
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)