473,763 Members | 5,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1841
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****@discuss ions.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"
AutoGenerateCol umns="False" PageSize="3">
<columns>
<asp:templateco lumn>
<itemtemplate >
<asp:label runat="server" Text='<%#
FixLongLine(Dat aBinder.Eval(Co ntainer, "DataItem.Strin gValue")) %>'
ID="Label1">
</asp:label>
</itemtemplate>
</asp:templatecol umn>
</columns>
</asp:datagrid>

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataS ource = CreateDataSourc e()
DataGrid1.DataB ind()
End If
End Sub

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

Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("IntegerValue" , GetType(Int32)) )
dt.Columns.Add( New DataColumn _
("StringValu e", 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) =
"Itemxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx
" + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSour ce
"Khumar" <Ha****@discuss ions.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.DataS ource = custInfo.getCus t("Select *
From Customers")
dataGrid1.DataB ind()

When I try to add your code:
<itemtemplate >
<asp:label runat="server"
Text='<%#
FixLongLine(Dat aBinder.Eval
(Container, "DataItem.Strin gValue")) %>'
ID="Label1">
</asp:label>
</itemtemplate>
</asp:templatecol umn>

the error shows in DataBinder.Eval :
DataBinder.Eval : 'System.Data.Da taRowView' 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"
AutoGenerateCo lumns="False" PageSize="3">
<columns>
<asp:templateco lumn>
<itemtemplate >
<asp:label runat="server" Text='<%#FixLongLine(Da taBinder.Eval (Container, "DataItem.Strin gValue")) %>'ID="Label1">
</asp:label>
</itemtemplate>
</asp:templatecol umn>
</columns>
</asp:datagrid>

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataS ource = CreateDataSourc e()
DataGrid1.DataB ind()
End If
End Sub

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

Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("IntegerValue" , GetType(Int32)) )
dt.Columns.Add( New DataColumn _
("StringValu e", 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) =
"Itemxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxx xxxxxxxxxxxxxxx xxx" + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSour ce
"Khumar" <Ha****@discuss ions.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"
AutoGenerateCol umns="False" PageSize="3">
<columns>
<asp:templateco lumn>
<itemtemplate >
<asp:label runat="server" Text='<%#
FixLongLine(Dat aBinder.Eval(Co ntainer, "DataItem.Strin gValue")) %>'
ID="Label1">
</asp:label>
</itemtemplate>
</asp:templatecol umn>
</columns>
</asp:datagrid>
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataS ource = CreateDataSourc e()
DataGrid1.DataB ind()
End If
End Sub
Public Function FixLongLine(ByV al strIn) As String
If Len(strIn) > 10 Then
Return Left(strIn, 10) & "..."
End If
Return strIn
End Function
Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("IntegerValue" , GetType(Int32)) )
dt.Columns.Add( New DataColumn _
("StringValu e", 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) =
"Itemxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxx
xxxxx
" + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSour ce
"Khumar" <Ha****@discuss ions.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
"StringValu e", yours could be "name". If so, replace StringValue with name.

DataItem.String Value

Let us know?

Ken

"Khumar" <an*******@disc ussions.microso ft.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.DataS ource = custInfo.getCus t("Select *
From Customers")
dataGrid1.DataB ind()

When I try to add your code:
<itemtemplate >
<asp:label runat="server"
Text='<%#
FixLongLine(Dat aBinder.Eval
(Container, "DataItem.Strin gValue")) %>'
ID="Label1">
</asp:label>
</itemtemplate>
</asp:templatecol umn>

the error shows in DataBinder.Eval :
DataBinder.Eval : 'System.Data.Da taRowView' 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"
AutoGenerateC olumns="False" PageSize="3">
<columns>
<asp:templateco lumn>
<itemtemplate >
<asp:label runat="server"

Text='<%#
FixLongLine(D ataBinder.Eval

(Container, "DataItem.Strin gValue")) %>'
ID="Label1" >
</asp:label>
</itemtemplate>
</asp:templatecol umn>
</columns>
</asp:datagrid>

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataS ource = CreateDataSourc e()
DataGrid1.DataB ind()
End If
End Sub

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

Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("IntegerValue" , GetType(Int32)) )
dt.Columns.Add( New DataColumn _
("StringValu e", 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) =
"Itemxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxx

xxxxxxxxxxxxxxx xxx
" + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSour ce
"Khumar" <Ha****@discuss ions.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:TemplateCo lumn HeaderText="Add ress Information">
<ItemTemplate >
<table border="0">
<tr>
<td align="right">< b>Street:</b></td>
<td><%# DataBinder.Eval (Container.Data Item, "Street") %></td>
</tr>
<tr>
<td align="right">< b>City:</b></td>
<td><%# DataBinder.Eval (Container.Data Item, "City") %></td>
</tr>
<tr>
<td align="right">< b>State:</b></td>
<td><%# DataBinder.Eval (Container.Data Item, "State") %></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateCol umn>


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

DataItem.String Value

Let us know?

Ken

"Khumar" <an*******@disc ussions.microso ft.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.DataS ource = custInfo.getCus t("Select *
From Customers")
dataGrid1.DataB ind()

When I try to add your code:
<itemtemplate >
<asp:label runat="server"
Text='<%#
FixLongLine(Dat aBinder.Eval
(Container, "DataItem.Strin gValue")) %>'
ID="Label1">
</asp:label>
</itemtemplate>
</asp:templatecol umn>

the error shows in DataBinder.Eval :
DataBinder.Eval : 'System.Data.Da taRowView' 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"
AutoGenerateC olumns="False" PageSize="3">
<columns>
<asp:templateco lumn>
<itemtemplate >
<asp:label runat="server"

Text='<%#
FixLongLine(D ataBinder.Eval

(Container, "DataItem.Strin gValue")) %>'
ID="Label1" >
</asp:label>
</itemtemplate>
</asp:templatecol umn>
</columns>
</asp:datagrid>

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataS ource = CreateDataSourc e()
DataGrid1.DataB ind()
End If
End Sub

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

Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("IntegerValue" , GetType(Int32)) )
dt.Columns.Add( New DataColumn _
("StringValu e", 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) =
"Itemxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxxxxxxxxxxx

xxxxxxxxxxxxxxx xxx
" + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSour ce
"Khumar" <Ha****@discuss ions.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
3512
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() == DialogResult.OK ) { this.dataGrid.SetDataBinding(null, null);
3
3909
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 gridcolumnstyle for all columns at the parent level. I have created a datastyle for every child level and I have assigned also gridcolumn styles to the components.
6
5322
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 works fine when we call the datatable and bind it to a data grid using datagridname.DataBind(), but I have an ASP table, with calculations using tbl_name.row(1).cells(1) and the result of the calculation is put in a specific row and cell. I have...
4
2687
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 width because the number of columns depends of something that I have (that is not important for this). Now, what I want is that the html table have always the same width of my datagrid because of alignment of both. NOTE: I must have (and want)...
3
2026
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 ...... ... </asp:datagrid> </td>
4
4533
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 "courseload". here's the fields of every table in my dataset. "Course" table CourseID
0
1162
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 this because I want to have multiple views of the same table. I have a ComboBox where I select the view I want. There are ten views, but only three tables. I have no problem when I have a one for one relationship view=tablestyle as shown here;
1
7355
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 whatever they want ... i dont need to do any special formatting just a straigh ot pivot tables usign sql server, asp.net, vb.net, OWC 10
1
6477
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 (FieldName-Authorised) which has a datatype bit through DataGrid but not sure how to go about it. Any Ideas Guys on this one, your help is greatly appreciated. This is the procedure used to populate the datagrid, The primary key for the table is EntryID which...
2
1729
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 automatically added...and it creates prob for me...i dont want that last null row to be present in the table...so how do i mk sure tat this last empty, null row dosent get attached to my table bound to the datagrid? p.s. if i mk my datagrid as read...
0
9387
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10148
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10002
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9823
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.