Datagrid and SQL Count

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.
 
J

Jl_G_0

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.
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top