Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Dear Users,
 
I habe an requirement on assigning a new line to String variable from dataset values please find out the suitable solution..Below is my code..
private string ContactDtlsToPDF(GridView grdC)
{
      ds = CntDetailsToPDF();
 
      for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
      {
            Body += ds.Tables[0].Rows[i]["Name"].ToString() + " " + ds.Tables[0].Rows[i]["Mobile"].ToString() + <"br/"> + " ";
      }
 
      return Body;
}
If my dataset has 5 Rows then it var body should hold 5 individual rows i have tried with br tag but not helpful...
Posted 15-Feb-13 19:31pm
sahmed3279
v2
Comments
Sergey Alexandrovich Kryukov at 16-Feb-13 1:33am
   
This "code" cannot even compile. Why it's so difficult? I see you put <> brackets outside "", concatenate strings...
Come on, learn System.String class and the simplest techniques first. If you help you, you will hardly learn it...
—SA
technovate at 16-Feb-13 1:42am
   
the is just a part code snippet i have posted i need any other solution..the above code is compiliong...Body +=ds.Tables[0].Rows[i]["Name"].ToString()+" "+ds.Tables[0].Rows[i]["Mobile"].ToString()+"<br/>";
Sandeep Mewara at 16-Feb-13 1:50am
   
Sounds like a homework where you have not spent much time and have not tried anything.
technovate at 16-Feb-13 1:55am
   
Just go through the code..
private string ContactDtlsToPDF(GridView grdC)
{
ds = CntDetailsToPDF();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
Body +=ds.Tables[0].Rows[i]["Name"].ToString()+" "+ds.Tables[0].Rows[i]["Mobile"].ToString()+"<br/>";
}
return Body;
}
 
where i've declared Body as a string if i have 3 rows in my dataset all the 3 three rows values are assigning it together...but i need it in a new line..i hope it;s clearn now..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I have done with
below code
Str = "<table id="" ctl00_contentplaceholder1_tblstring2="" style="" cellpadding="" 0="" cellspacing=""><tr>"
        Str += "<td id="" ctl00_contentplaceholder1_txtmsg1="" style="" left="">"
        arrLines = Split(TxtMsg.Text, vbCrLf)
        For Each strLine In arrLines
            Str += "</td></tr>" & strLine & "<tr><td>"
        Next
        Str += "</td></tr><tr>"
        Str+="</tr></table>"
May be This Will Help you
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Please make changes in following code.
private string ContactDtlsToPDF(GridView grdC)
{
      ds = CntDetailsToPDF();
 
      for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
      {
            if(Body == "")
            Body = ds.Tables[0].Rows[i]["Name"].ToString() + " " + ds.Tables[0].Rows[i]["Mobile"].ToString()";
else
Body += Environment.NewLine + ds.Tables[0].Rows[i]["Name"].ToString() + " " + ds.Tables[0].Rows[i]["Mobile"].ToString()";
      }
 
      return Body;
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 235
1 Sergey Alexandrovich Kryukov 120
2 Richard MacCutchan 100
3 kbrandwijk 85
4 Vinay Mistry 70
0 Sergey Alexandrovich Kryukov 9,056
1 OriginalGriff 8,041
2 CPallini 2,613
3 Richard MacCutchan 2,221
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 17 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100