Datagrid and SQL Count

  • Thread starter Thread starter Jl_G_0
  • Start date Start date
J

Jl_G_0

Hey all.
I have one question here regarding a datagrid. I have a datagrid with
one hyperlinkcolumn and some boundcolumns. I want to add one more
column, filled by how many subprojects are under that project. To find
out this information, I can use 'SQL Count' and with executescalar() I
should get the answer on a variable. But how can I get this answer on
every line of the datagrid ... using a templatecolumn ?
I'm having a hard time creating this template column... I just need to
learn how to executeScalar from the Datagrid column, and how to pass
the parameters to the SQL query using the first column of the datagrid
(Name).

Just a few tips might put me on the right track. Thanks.
 
Found out a solution.

Created a Function (Public) and it executes the ExecuteScalar with a
parameter as variable. This variable is the parameter of the SQL
String.

Public Function readBase(Param As String)
conecBases.Open()
yComan.Parameters.AddWithValue("@choose", Param)
yAnswer = yComan.ExecuteScalar()
yComan.Parameters.Clear()
conecBases.Close()
return yAnswer
End Function

---------------------

On the datagrid - TemplateColumn:
<ItemTemplate>
<%# readBase(DataBinder.Eval(Container.DataItem,"Name")) %>
</ItemTemplate>

I dont know very well how to use DataBinder.Eval ... but I know that it
worked fine.

If anyone knows a good tutorial so I can learn more about it, please
post. Thx.
 
It would be more efficient if you return your computed column as part of
query resultset and simply bind hyperlink to the column. Or you can use
DataGrid_ItemDataBound event where you can get value of the current column
and manually bind hyperlink to the result of your function based on this
parameter.
 
Back
Top