Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

Adding User Control to each cell in a DataGrid column using attributes

Hello,

I have a User Control that I can happily add to a page using, for example:

<myControl:Chart id="chart1" probL="0.15" prob="0.2" probU="0.35" runat="Server />

This works great and displays the image that the control draws on the fly. The image is a small graph based on the three decimal attributes.
However, I have a DataGrid control on the page that has three columns that contain the probL, prob and ProbU values for a number of rows of data (these are in a DataSet and the DataGrid is then bound to the DataSet) and I want to have a 4th column that has the graph produced by my MyControl:Chart in each cell using the three attributes on that row. I'm sure this is quite straight forward, but all of the examples I've found so far fall short of how to do this with a User Control. The datagrid should end up something like:

probL     Prob     probU                                                Graph
-----------------------------------------------------------------------------------------------------------
0.123     0.222    0.345     [image: graph based on values in row 1 using <MyControl:Chart>]
0.011     0.079    0.101     [image: graph based on values in row 2 using <MyControl:Chart>]
.
.
.. and so on

Cheers for any help.
0
andycrellin
Asked:
andycrellin
  • 2
  • 2
1 Solution
 
laotzi2000Commented:
Try add this to the datagrid, you should do the same thing to prob and probU as to probL
      
                  <Columns>
                              <asp:TemplateColumn HeaderText="Graph">
                              <ItemTemplate>
<myControl:Chart id="chart1" probL=<%# DataBinder.Eval(Container.DataItem, "probL") %> prob="0.2" probU="0.35" runat="Server />
                                                                                </ItemTemplate>
                              </asp:TemplateColumn>
                        </Columns>
0
 
andycrellinAuthor Commented:
Sorry - should have clarified: How would I do this in code? The DataGrid is empty at dev. time and the columns are built (when the page is called) in the code-behind module. Or would this method still work?
Thanks for the quick response by the way!
0
 
laotzi2000Commented:
I think this should still work with other columns built in code

And you can do it in code too,
You can create a user control:
Dim chart1 as New Chart
0
 
andycrellinAuthor Commented:
Just tried it and it's perfect. Was stumped for a little while with a String to Decimal conversion error before I realised that by the time probL gets into the datagrid it's in "0.00%" format! I used the method set out first - just means I need to sort out the column ordering but that should be simple enough.
You managed to answer in 10 lines what I must have trawled through 20-odd tutorials to try to find out. Cheers.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now