Ramani Sandeep's Blog

DotNetting – Fast , Easy Way of Developing Applications

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

Posted by ramanisandeep on May 13, 2009

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>

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>