473,394 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Table or Datagrid

Hello,

Im new in asp.net especially in web base application.
I want to ask about datagrid. I had shown my table on
datagrid, and what I want to ask is how to set the column
height fixed? Because when I have a long word it
automatically set new line instead of hide it. I want it
to be hide like this 928192... with 3 dot at the end of
the word if it is to long.

Is it possible to do it?

Thanks alll
Nov 19 '05 #1
6 1819
You need to write a method that will take a string as a parameter and return
a truncated string with dots at the end if the input string is too long.
Having done that, you can use the string in your databind expression.

Alternatively you can handle ItemDataBound event to catch the cell value and
to truncate it in the code using the same function.

Eliyahu

"Khumar" <Ha****@discussions.microsoft.com> wrote in message
news:3b****************************@phx.gbl...
Hello,

Im new in asp.net especially in web base application.
I want to ask about datagrid. I had shown my table on
datagrid, and what I want to ask is how to set the column
height fixed? Because when I have a long word it
automatically set new line instead of hide it. I want it
to be hide like this 928192... with 3 dot at the end of
the word if it is to long.

Is it possible to do it?

Thanks alll

Nov 19 '05 #2
The easiest way is to use a helper function that trims the text to the
correct length and adds the ellipsis. Here's some code that uses only the
first ten characters, let us know if it helps?

Ken
Microsoft MVP [ASP.NET]
Toronto

<asp:datagrid id="DataGrid1" runat="server"
AutoGenerateColumns="False" PageSize="3">
<columns>
<asp:templatecolumn>
<itemtemplate>
<asp:label runat="server" Text='<%#
FixLongLine(DataBinder.Eval(Container, "DataItem.StringValue")) %>'
ID="Label1">
</asp:label>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub

Public Function FixLongLine(ByVal strIn) As String
If Len(strIn) > 10 Then
Return Left(strIn, 10) & "..."
End If
Return strIn
End Function

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) =
"Itemxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx
" + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
"Khumar" <Ha****@discussions.microsoft.com> wrote in message
news:3b****************************@phx.gbl...
Hello,

Im new in asp.net especially in web base application.
I want to ask about datagrid. I had shown my table on
datagrid, and what I want to ask is how to set the column
height fixed? Because when I have a long word it
automatically set new line instead of hide it. I want it
to be hide like this 928192... with 3 dot at the end of
the word if it is to long.

Is it possible to do it?

Thanks alll


Nov 19 '05 #3
Hello Ken,

Im trying your code and its work, but it doesnt work with
my code. This is how I connect to database. I create a
class which allow connection to database. In class I
create dataset module so it return dataset.
I connect from database to datagrid is like this
dataGrid1.DataSource = custInfo.getCust("Select *
From Customers")
dataGrid1.DataBind()

When I try to add your code:
<itemtemplate>
<asp:label runat="server"
Text='<%#
FixLongLine(DataBinder.Eval
(Container, "DataItem.StringValue")) %>'
ID="Label1">
</asp:label>
</itemtemplate>
</asp:templatecolumn>

the error shows in DataBinder.Eval:
DataBinder.Eval: 'System.Data.DataRowView' does not
contain a property with the name StringValue.

Is there any problem with my connection to database?
Thanks
-----Original Message-----
The easiest way is to use a helper function that trims the text to thecorrect length and adds the ellipsis. Here's some code that uses only thefirst ten characters, let us know if it helps?

Ken
Microsoft MVP [ASP.NET]
Toronto

<asp:datagrid id="DataGrid1" runat="server"
AutoGenerateColumns="False" PageSize="3">
<columns>
<asp:templatecolumn>
<itemtemplate>
<asp:label runat="server" Text='<%#FixLongLine(DataBinder.Eval (Container, "DataItem.StringValue")) %>'ID="Label1">
</asp:label>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub

Public Function FixLongLine(ByVal strIn) As String
If Len(strIn) > 10 Then
Return Left(strIn, 10) & "..."
End If
Return strIn
End Function

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) =
"Itemxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx xxxxxxxxxxxxxxxxxx" + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
"Khumar" <Ha****@discussions.microsoft.com> wrote in messagenews:3b****************************@phx.gbl...
Hello,

Im new in asp.net especially in web base application.
I want to ask about datagrid. I had shown my table on
datagrid, and what I want to ask is how to set the column height fixed? Because when I have a long word it
automatically set new line instead of hide it. I want it to be hide like this 928192... with 3 dot at the end of
the word if it is to long.

Is it possible to do it?

Thanks alll


.

Nov 19 '05 #4
Hello Ken Cox [Microsoft MVP],

Instead of "..." you could also use "&hellip;", which is the HTML code for
a horizontal ellipsis.

--
Matt Berther
http://www.mattberther.com
The easiest way is to use a helper function that trims the text to the
correct length and adds the ellipsis. Here's some code that uses only
the first ten characters, let us know if it helps?

Ken
Microsoft MVP [ASP.NET]
Toronto
<asp:datagrid id="DataGrid1" runat="server"
AutoGenerateColumns="False" PageSize="3">
<columns>
<asp:templatecolumn>
<itemtemplate>
<asp:label runat="server" Text='<%#
FixLongLine(DataBinder.Eval(Container, "DataItem.StringValue")) %>'
ID="Label1">
</asp:label>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub
Public Function FixLongLine(ByVal strIn) As String
If Len(strIn) > 10 Then
Return Left(strIn, 10) & "..."
End If
Return strIn
End Function
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) =
"Itemxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx
xxxxx
" + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
"Khumar" <Ha****@discussions.microsoft.com> wrote in message
news:3b****************************@phx.gbl...
Hello,

Im new in asp.net especially in web base application.
I want to ask about datagrid. I had shown my table on
datagrid, and what I want to ask is how to set the column
height fixed? Because when I have a long word it
automatically set new line instead of hide it. I want it
to be hide like this 928192... with 3 dot at the end of
the word if it is to long.
Is it possible to do it?

Thanks alll


Nov 19 '05 #5
You need to tell the helper the name of *your* data item. Mine was
"StringValue", yours could be "name". If so, replace StringValue with name.

DataItem.StringValue

Let us know?

Ken

"Khumar" <an*******@discussions.microsoft.com> wrote in message
news:3b****************************@phx.gbl...
Hello Ken,

Im trying your code and its work, but it doesnt work with
my code. This is how I connect to database. I create a
class which allow connection to database. In class I
create dataset module so it return dataset.
I connect from database to datagrid is like this
dataGrid1.DataSource = custInfo.getCust("Select *
From Customers")
dataGrid1.DataBind()

When I try to add your code:
<itemtemplate>
<asp:label runat="server"
Text='<%#
FixLongLine(DataBinder.Eval
(Container, "DataItem.StringValue")) %>'
ID="Label1">
</asp:label>
</itemtemplate>
</asp:templatecolumn>

the error shows in DataBinder.Eval:
DataBinder.Eval: 'System.Data.DataRowView' does not
contain a property with the name StringValue.

Is there any problem with my connection to database?
Thanks
-----Original Message-----
The easiest way is to use a helper function that trims

the text to the
correct length and adds the ellipsis. Here's some code

that uses only the
first ten characters, let us know if it helps?

Ken
Microsoft MVP [ASP.NET]
Toronto

<asp:datagrid id="DataGrid1" runat="server"
AutoGenerateColumns="False" PageSize="3">
<columns>
<asp:templatecolumn>
<itemtemplate>
<asp:label runat="server"

Text='<%#
FixLongLine(DataBinder.Eval

(Container, "DataItem.StringValue")) %>'
ID="Label1">
</asp:label>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub

Public Function FixLongLine(ByVal strIn) As String
If Len(strIn) > 10 Then
Return Left(strIn, 10) & "..."
End If
Return strIn
End Function

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) =
"Itemxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxx

xxxxxxxxxxxxxxxxxx
" + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
"Khumar" <Ha****@discussions.microsoft.com> wrote in

message
news:3b****************************@phx.gbl...
Hello,

Im new in asp.net especially in web base application.
I want to ask about datagrid. I had shown my table on
datagrid, and what I want to ask is how to set the column height fixed? Because when I have a long word it
automatically set new line instead of hide it. I want it to be hide like this 928192... with 3 dot at the end of
the word if it is to long.

Is it possible to do it?

Thanks alll


.


Nov 19 '05 #6
Ken,

Could you tell me how could I enable edit in template column field. I have a
edit butten in datagrid, when I click it, data bound column change to textbox
but not template column. I have table in template column. Here is my code:

Thanks for help,
cms123

<asp:TemplateColumn HeaderText="Address Information">
<ItemTemplate>
<table border="0">
<tr>
<td align="right"><b>Street:</b></td>
<td><%# DataBinder.Eval(Container.DataItem, "Street") %></td>
</tr>
<tr>
<td align="right"><b>City:</b></td>
<td><%# DataBinder.Eval(Container.DataItem, "City") %></td>
</tr>
<tr>
<td align="right"><b>State:</b></td>
<td><%# DataBinder.Eval(Container.DataItem, "State") %></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateColumn>


"Ken Cox [Microsoft MVP]" wrote:
You need to tell the helper the name of *your* data item. Mine was
"StringValue", yours could be "name". If so, replace StringValue with name.

DataItem.StringValue

Let us know?

Ken

"Khumar" <an*******@discussions.microsoft.com> wrote in message
news:3b****************************@phx.gbl...
Hello Ken,

Im trying your code and its work, but it doesnt work with
my code. This is how I connect to database. I create a
class which allow connection to database. In class I
create dataset module so it return dataset.
I connect from database to datagrid is like this
dataGrid1.DataSource = custInfo.getCust("Select *
From Customers")
dataGrid1.DataBind()

When I try to add your code:
<itemtemplate>
<asp:label runat="server"
Text='<%#
FixLongLine(DataBinder.Eval
(Container, "DataItem.StringValue")) %>'
ID="Label1">
</asp:label>
</itemtemplate>
</asp:templatecolumn>

the error shows in DataBinder.Eval:
DataBinder.Eval: 'System.Data.DataRowView' does not
contain a property with the name StringValue.

Is there any problem with my connection to database?
Thanks
-----Original Message-----
The easiest way is to use a helper function that trims

the text to the
correct length and adds the ellipsis. Here's some code

that uses only the
first ten characters, let us know if it helps?

Ken
Microsoft MVP [ASP.NET]
Toronto

<asp:datagrid id="DataGrid1" runat="server"
AutoGenerateColumns="False" PageSize="3">
<columns>
<asp:templatecolumn>
<itemtemplate>
<asp:label runat="server"

Text='<%#
FixLongLine(DataBinder.Eval

(Container, "DataItem.StringValue")) %>'
ID="Label1">
</asp:label>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub

Public Function FixLongLine(ByVal strIn) As String
If Len(strIn) > 10 Then
Return Left(strIn, 10) & "..."
End If
Return strIn
End Function

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) =
"Itemxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxx

xxxxxxxxxxxxxxxxxx
" + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
"Khumar" <Ha****@discussions.microsoft.com> wrote in

message
news:3b****************************@phx.gbl...
Hello,

Im new in asp.net especially in web base application.
I want to ask about datagrid. I had shown my table on
datagrid, and what I want to ask is how to set the

column
height fixed? Because when I have a long word it
automatically set new line instead of hide it. I want

it
to be hide like this 928192... with 3 dot at the end of
the word if it is to long.

Is it possible to do it?

Thanks alll

.


Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Soul | last post by:
Hi, I have a DataGrid which works. But if I load a new table to the DataGrid, it will still show those old data I load earlier. private void loadTableA() { if ( openFileDialog.ShowDialog()...
3
by: Quetzal | last post by:
Hello, I have a dataset populated using an XML file. The schema has hierarchical components. Let's say <a><b></b></a>. I have created a datagrid and I have assigned a datastyle and then...
6
by: coleenholley | last post by:
I have a Class Module written in VB that calls an RPC (written in COBOL) we have written code to read the data from the RPC, and we create a temporary datatable to store the data from the RPC. This...
4
by: ruca | last post by:
Hi How can I get a html control in my code? I have a html table that I want the width is defined in code at run time, i.e., I have this table and I have a datagrid. This datagrid have a variable...
3
by: CalSun | last post by:
I have a datagrid with about 15 columns bound at run time. I create an html table and have this datagrid inside. <table align=center width="90%"> <tr> <td> <asp:datagrid ...... ......
4
by: jaYPee | last post by:
I have 1 dataset called "dataset1" that contains 2 tables called "course" and "courseload". in my form i have a datagrid. the datasource of this datagrid is "dataset1" and the datamember is...
0
by: dbuchanan | last post by:
How do I make multiple DataGridTableStyles serve the same table? (I can get multiple styles for the same datagrid, but not multple styles for the same *table* on the same datagrid) I want to do...
1
by: kingster | last post by:
Hi, I have a regular dataset and all i want to do is make a pivot table display in a browser with the datasource of the pivot table to be this dataset and then the end-user will be able to do...
1
by: Sharon | last post by:
Hello All, Is it possible to update Sql Table through DataGrid. I have a DataGrid which is being populated through a stored procedure, all i wanted to do is to update one field...
2
by: harini | last post by:
i hv a datagrid to which i hv bound a table...i hv the table columns to be editable...i.e read only = false....now i hv a problem...in the table there seems to be a row at the end having no values...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.