0

How to create a dynamic table from java script?I am fetching a record from database and storing into variable and adding that value to table cell. Here I put some text not actual value.

In cs file's button click event I doing like this

StringBuilder sb = new StringBuilder();
sb.Append(@"<script language='javascript'>");
sb.Append("<table><tbody><tr><td>Information</td></tr></tbody></table>");
sb.Append(@"</script>");

if (!Page.ClientScript.IsClientScriptBlockRegistered(Page.GetType(), "HeyPopup"))

ClientScript.RegisterClientScriptBlock(Page.GetType(), "HeyPopup", sb.ToString());

But I am unable to see Information.

1 Answer 1

1

you must add document.Write in your script

so replace with

sb.Append("document.write('<table><tbody><tr><td>Information</td></tr></tbody></table>');");
Sign up to request clarification or add additional context in comments.

4 Comments

If there is condition like ,if(str1 == 'gfgfg'){<tr><td>gfgf</td></tr>}?Does i need to do in C# or javascript?
I don't inderstood Jui, do you want add condition ?
string s1 = "Computer"; StringBuilder sb = new StringBuilder(); sb.Append(@"<script language='javascript'>"); sb.Append("<table><tbody><tr><td>Information</td></tr>") if(s1 == "Computer" ) sb.Append("<tr><td>s1</td></tr>"); </tbody></table>"); sb.Append(@"</script>"); if (!Page.ClientScript.IsClientScriptBlockRegistered(Page.GetType(), "HeyPopup")) ClientScript.RegisterClientScriptBlock(Page.GetType(), "HeyPopup", sb.ToString()); Then how to write document.write for all.
Jui try with : string s1 = "Computer"; StringBuilder sb = new StringBuilder(); sb.Append(@"<script language='javascript'>"); sb.Append("<table><tbody><tr><td>Information</td></tr>"); if(s1 == "Computer" ) sb.Append("<tr><td>s1</td></tr>"); sb.Append("</tbody></table>"); sb.Append(@"</script>");

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.