Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
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..
C#
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
v2
Comments
Sergey Alexandrovich Kryukov 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
sahmed3 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 16-Feb-13 1:50am    
Sounds like a homework where you have not spent much time and have not tried anything.
sahmed3 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..

I have done with
below code
VB
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
 
Share this answer
 
Please make changes in following code.
C#
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;
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900