-1

SqlDataReader myreader; myreader = cmmd.ExecuteReader();

                        StringBuilder sb = new StringBuilder();
                        sb.Append("<b>Vaccine</b>&nbsp;&nbsp;&nbsp;<b> Vaccination Date</b>&nbsp;&nbsp;&nbsp;<b> Vaccination Due Date</b>&nbsp;&nbsp;&nbsp;<b> Incomplete Vaccination </b>&nbsp;&nbsp;&nbsp;<b>Dose No.</b>&nbsp;&nbsp;&nbsp;<b> Remarks </b><br/><br/>");
                        while (myreader.Read())
                            {
                                    sb.Append(myreader["VaccineID"]);
                                    sb.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                                    sb.Append(myreader["DateOFVaccine"]);
                                    sb.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                                    sb.Append(myreader["NextVaccinationDueDate"]);
                                    sb.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                                    sb.Append(myreader["AnyIncompleteImmunization"]);
                                    sb.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                                    sb.Append(myreader["DoseNumber"]);
                                    sb.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                                    sb.Append(myreader["Remark1"]);
                                    sb.Append("<br/>");
                            }
                        lblDisplayDetails.Text = sb.ToString();
                        myreader.Close();

WHAT EXACTLY I WANT IS TO RETRIEVE DATA(may be from separate table) AND THEN DISPLAY THEM PUTTING SOME STYLE(font,color etc).

Is retrieving from multiple table is possible in gridview ? I could use the DataReader, but how to display them in style(font,color etc) ? Regards Indranil

3
  • 6
    Yuk. I really hope you're not developing that for the NHS!
    – UpTheCreek
    Apr 28, 2010 at 10:06
  • i think this will work for sure or you can care one div element and do divId.innerhtml = sb.ToString(); Apr 28, 2010 at 10:07
  • 3
    This code is honestly giving me the creeps right now. Apr 28, 2010 at 14:20

2 Answers 2

13

2 words!

GridView

&

Repeater
1
  • 4
    That is definitely the way to go. Programmers are awesome at "i know you asked for X, but really, you need to use Z" Apr 28, 2010 at 10:08
0

You need to use the Literal control, and since your string contains html tags, you'll need to set the control's Mode to PassThrough

This is a very dangerous thing to do, because if a hacker or even a digruntled user somehow gets the string <script>alert('haha i hacked your site')</script> into any of your database cells, such as "Remark1", then you've just fallen victim to an XSS attack

You'll need to call Server.HtmlEncode on all of your myreader fields:

sb.Append(Server.HtmlEncode(myreader["Remark1"]));

like this page recommends: http://msdn.microsoft.com/en-us/library/a2a4yykt.aspx

1
  • 1
    thanks for the accept, but please consider researching gridview & repeater. You're not in PHP-land any more! May 11, 2010 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.