Reply
datagrid to display operation/function
Old 06-19-2008, 05:20 AM datagrid to display operation/function
Nazi370's Avatar
Skilled Talker

Posts: 70
Name: Nazirul
Trades: 0
Good Day !

usually datagrid only display data directly from the database.

this is how i usually did it :

Quote:
Private Sub FillGrid()
Dim oConn As SqlConnection oConn = New SqlConnection(ConfigurationSettings.AppSettings("S MPBDB"))

Filtering()

Dim sqldataAdapter1 As SqlDataAdapter = New SqlDataAdapter(Session("mySelectQuery"), ConfigurationSettings.AppSettings("SMPBDB"))

Dim dsSchedule As DataSet = New DataSet sqldataAdapter1.Fill(dsSchedule)

dgUser.DataSource = dsSchedule

dgUser.DataBind()

oConn.Close()

End Sub
pass it into --->

Quote:
PrivateSub Filtering()
Dim SelectQry, mySelectQuery AsString
SelectQry = "SELECT * FROM Rekod_Kursus INNER JOIN SenaraiPeserta ON Rekod_Kursus.NoRujukan = SenaraiPeserta.NoRujukan"

Dim ThnMula AsString = Trim(ddlThnMula.SelectedValue)
If (ThnMula <> "Semua") Then
mySelectQuery = SelectQry & " where Rekod_Kursus.ThnMula = '" & ThnMula & "' Order by Rekod_Kursus.ThnMula"

EndIf
Session("mySelectQuery") = mySelectQuery


EndSub
then recall it in datagrid by :

Quote:

<
Columns>

<
asp:HyperLinkColumnDataNavigateUrlField="ID"DataNavigateUrlFormatString="http:/SMPB/kursusMaintainB.aspx?UserID={0}" DataTextField="NoRujukan"HeaderText="No Rujukan"><HeaderStyleWidth="130px"></HeaderStyle></asp:HyperLinkColumn>

<
asp:BoundColumnDataField="FullName"HeaderText="Nama Pegawai"></asp:BoundColumn>

<
asp:BoundColumnDataField="JumlahJam"HeaderText="Jumlah Jam"></asp:BoundColumn>
</Columns>
where which i bold is the column name in the database derived from *.
i want to do some calculation to replace ''JumlahJam" with one function.
how can i do it? if i replace JumlahJam with another name that is not from the database. it will yield error message

A field or property with the name 'myFunction' was not found on the selected datasource.

how do i replace it with function?... thanks in advance

-Nazirul
Nazi370 is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 06-19-2008, 12:27 PM Re: datagrid to display operation/function
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,674
Name: John Alexander
Trades: 0
Project the calculation from your database.

Select Col1, Col2, Col1 * Col2 / 5 As Col3 From Table1
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 06-19-2008, 06:17 PM Re: datagrid to display operation/function
RabidSniper's Avatar
Skilled Talker

Posts: 57
Name: Jesse
Location: Phoenix, AZ
Trades: 0
Im not 100% positive but I think the DataGrid supports ItemTemplates as well right? So instead of the BoundField you can specify an ItemTemplate that can contains all the gooey logic you want to include, and if you use the <%#Bind("FIELD_NAME")%> declaration within a template it still does two way databinding for you. At least thats the way it works with GridView, not sure about the differences..
RabidSniper is offline
Reply With Quote
View Public Profile
 
Old 06-19-2008, 09:09 PM Re: datagrid to display operation/function
Nazi370's Avatar
Skilled Talker

Posts: 70
Name: Nazirul
Trades: 0
let say i have column name 'marks' ... i want to calculate it based on 'year'.. where there are two tables involved... QuizRecord and Participant...

the column 'marks' and 'year' is in QuizRecord and join to participant by ReferenceNo where the participantName is in participant
is it possible in SQL Query like example from John ?

such

if participant.year = QuizRecord.year
then quizRecord.marks + quizRecord.marks

it will add the same value...

does i make it clear?
Nazi370 is offline
Reply With Quote
View Public Profile
 
Old 06-19-2008, 10:32 PM Re: datagrid to display operation/function
Nazi370's Avatar
Skilled Talker

Posts: 70
Name: Nazirul
Trades: 0
finally.. .thanks John for the Idea... you are great man !

i've used Sum(tableName) ...

thanks for the comment RabidSniper
Nazi370 is offline
Reply With Quote
View Public Profile
 
Old 06-20-2008, 12:20 PM Re: datagrid to display operation/function
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,674
Name: John Alexander
Trades: 0
No problem. It's not always the best approach - sometimes it gets me into trouble by not letting me learn as much - but it can be helpful to try changing things upstream if downstream isn't working.
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to datagrid to display operation/function
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11001 seconds with 13 queries