How to call a function from .aspx.cs file to .aspx file


Hi, U can use the .cs side function in .aspx side something below given method

I have created the following method in .cs side

public int GetNoOfForums(int groupId)
{
ForumCollection forums = new ForumCollection();
return forums.GetNoOfForums(groupId);
}

After that we call that method in  .aspx  something like below.

<asp:DataList ID=”dlstGroup” runat=”server” OnItemCommand=”dlstGroup_ItemCommand”
OnItemDataBound=”dlstGroup_ItemDataBound” >
<HeaderTemplate>
<tr>
<th>
<b>Created By</b>
</th>

<th style=”font-weight: bold;”>
No. of Forums
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align=”left”>
<%#Eval(“CreatedByUserName”) %>
</td>
<td align=”left”>
<asp:Label ID=”lblStatus” runat=”server” Text=’ <%#Eval(“Status”) %>’></asp:Label>
</td>
<td align=”center”>
<%#GetNoOfForums(Convert.ToInt32(Eval(“GroupID”)))%>
</td>

</tr>
</ItemTemplate>
</asp:DataList>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s