how can i use a javascript in gridview row
I want to use a flash chart in a gridview. you can see my codes in below:
DataTable tbl = new DataTable();
tbl.Columns.Add("chart");
DataRow rw;
rw = tbl.NewRow();
rw["chart"] = @"<div id=""chart5Div""></div>
<script type=""text/javascript"">
var chart = new FusionCharts(""Charts/FCF_MSLine.swf"", ""ChId1"", ""500"", ""300"");
var strXml = ""<graph numdivlines='4' lineThickness='3' showValues='0' numVDivLines='10' formatNumberScale='1' rotateNames='1' decimalPrecision='1' anchorRadius='2' anchorBgAlpha='0' numberPrefix='$' divLineAlpha='30' showAlternateHGridColor='1' yAxisMinValue='800000' shadowAlpha='50' >"";
strXml += ""<categories >"";
strXml += ""<category Name='Jan' />"";
strXml += ""<category Name='Feb' />"";
strXml += ""<category Name='Mar' />"";
strXml += ""<category Name='Apr' />"";
strXml += ""</categories >"";
strXml += ""<dataset seriesName='Current Year' color='A66EDD' anchorBorderColor='A66EDD' anchorRadius='4'>"";
strXml += ""<set value='1127654' />"";
strXml += ""<set value='1226234' />"";
strXml += ""<set value='1299456' />"";
strXml += ""<set value='1311565' />"";
strXml += ""</dataset>"";
strXml += ""</graph>"";
chart.se开发者_开发问答tDataXML(strXml);
chart.render(""chart5Div"");
</script>";
tbl.Rows.Add(rw);
GridView1.DataSource = tbl;
GridView1.DataBind();
I must create dynamicly my datasource. But i can see just string value instead of my chart in gridview when page running. But chart code is running correctly between table tags. How can i use these codes in gridview??
KR
What kind of column are you using in grid-view to show "chart" data? That column would be (correctly) escaping your html. I would suggest using TemplateColumn with dive and all your script can be put in markup (aspx) page. The dynamic part within your script can come from data row using data binding expressions (<%# Eval('Column Name') %>).
精彩评论