Hi,
I'm trying to write a SQL SELECT statement where the phone numer ("telnr") is divided on three rows. How do I write a newline? I've tried \n, NEWLINE, and a few others.
Thanks in advance!
Pettrer, Sweden (VB, Sql Server, VWD Express, Asp.Net 2.0)
Code:
SelectCommand
="SELECT [gID], [enamn], [fnamn], telnr1 + ' ' + telnr2 + ' ' + telnr3 As telnr, [epost] FROM...The corresponding gridview's cell's value is08-43 244 234 08-432
23 08-424333
and should be
08-43 244 234
08-432 23
08-424333
If you want to display it on your page,you can add <br> to break line.
SelectCommand
="SELECT [gID], [enamn], [fnamn], telnr1 + '<br />' + telnr2 + '<br />' + telnr3 As telnr, [epost] FROM...
|||Hi,
Thanks but that doesn't work in tool tips. I think I'll solve it with commas instead. It's still an intesting question though.
Best,
Pettrer
|||In my opinion, this should be handled in the presentation layer, not in the stored procedure returning the data.|||Hello,
Couldn't get that to work either. However, I converted the phone numbers nicely. MIght be of value to someone else.
aspx page (SELECT command for gridview):
SelectCommand
="SELECT [gID], [enamn], [fnamn], (COALESCE(telnr1,'') + ', ' + COALESCE(telnr2,'') + ', ' + COALESCE(telnr3,'')) As telnr, [epost] FROM [Grund] (etc.)
aspx.vb page:
ProtectedSub MemberGridView_RowDataBound(ByVal senderAsObject,ByVal eAs System.Web.UI.WebControls.GridViewRowEventArgs)Handles MemberGridView.RowDataBound
If e.Row.RowType = DataControlRowType.DataRowThen'gets a phone symbol in the gridview if there is a phone no in the db. I have three phone no fields and the code below takes out the additional commas if they shouldn't be there (08-43243, , , becomes 08-43243 for example)Dim telnrAsString = e.Row.Cells(4).TextIf telnr.Length <= 5Then e.Row.Cells(4).Text =" "If telnr.Length > 5Thene.Row.Cells(4).Text =
"<img src="http://pics.10026.com/?src="imgadmin/tfn.gif"">"Dim MyCharAsChar() = {" "c, ","c}'h?r tas mellanslag och komman utanf?r telnr borttelnr = telnr.TrimStart(MyChar)
telnr = telnr.TrimEnd(MyChar)
e.Row.Cells(4).ToolTip = Replace(telnr,
" ,","")'tar bort ev " ," i mittenEndIfPettrer
|||The following code works fine,you can try it :
<%@. Page Language="C#" AutoEventWireup="true" ValidateRequest="false" CodeFile="Gridview_Test.aspx.cs" Inherits="Gridview_Test" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> </div> <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False"> <Columns> <asp:BoundField DataField="Column1" HeaderText="Column1" HtmlEncode="False" ReadOnly="True" SortExpression="Column1" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:pubsConnectionString%>" SelectCommand="SELECT [col] +'Remember to set htmlencode to false.|||
</asp:SqlDataSource> </form></body></html>
yyy8347:
The following code works fine
Maybe, or maybe not, anyway I do not see how it applies to this topic... or to this forum...?
-LV
;-)
P
No comments:
Post a Comment