Display custom data in ASP.Net FormView

danielivanov2
danielivanov2 used Ask the Experts™
on
I have a FormView in ASP.Net/C#, used only with Item Template, that it is supposed to display:
1. data (formatted or not) from database
2. computed data  (formatted or not), like: <%# Eval("Field1")/Eval("Field2") %> -Eval("Field2") should be checked against null or 0 value, in order to avoid division by 0 error
3. values of session variables and/or hidden fields

section 1 is clear (code attached, works fine), however I don't know how to manage 2 and 3. Any example would be helpful. Thanks


<asp:FormView ID="FormViewCaseDetails" runat="server">
            <RowStyle CssClass="RowStyle" />          
            <ItemTemplate>
                <hr />
                <h3><%# Eval("Company_Name")%></h3>
                <table border="0">
                    <tr>
                        <td class="FormViewCaseDetailsLabel">
                            Id Caz:</td>
                        <td><%# Eval("Case_Id")%></td>
                        <td class="FormViewCaseDetailsLabel">
                            Status Curent Caz:</td>
                        <td>
                            <asp:Label ID="LabelCaseStatus" runat="server" Text='<%# Eval("Case_Status")%>' />
                        </td>
                        <td class="FormViewCaseDetailsLabel">
                            (KPI) ARPU:</td>                            
                        <td><%# Eval("ARPU","{0:C3}")%></td>
                    </tr>
                    <tr>
                        <td class="FormViewCaseDetailsLabel">
                            Tip Caz:</td>
                        <td><%# Eval("Case_Channel")+"-"+Eval("Case_Type")%></td>
                        <td class="FormViewCaseDetailsLabel">
                            Data Status:</td>
                        <td><%# Eval("Case_Status_Date","{0:d}")%></td>
                        <td class="FormViewCaseDetailsLabel">
                            (KPI) PPM:</td>
                        <td><%# Eval("PPM","{0:C3}")%></td>
                    </tr>
                    <tr>
                        <td class="FormViewCaseDetailsLabel">
                            Urgent?:</td>
                        <td>
                            <asp:Label ID="LabelUrgentInd" runat="server"
                                 Text='<%# Eval("Urgent_Ind")%>'>
                            </asp:Label>
                        </td>
                        <td class="FormViewCaseDetailsLabel">
                            User curent:</td>
                        <td>
                            <asp:Label ID="LabelUserName" runat="server" Text='<%# Eval("UserName")%>' />
                        </td>
                        <td class="FormViewCaseDetailsLabel">
                            (KPI) NPV:</td>
                        <td><%# Eval("NPV")%></td>
                    </tr>
                    <tr>
                        <td class="FormViewCaseDetailsLabel">
                            Customer Id(s):</td>
                        <%--<td><%# Eval("Customer_Id")%></td>--%>
                        <td>
                            <asp:Label ID="LabelCustomerId" 
                            runat="server" Text='<%# Eval("Customer_Id")%>'>
                            </asp:Label>                                
                        </td>
                        <td class="FormViewCaseDetailsLabel">
                            Total SAI:</td>
                        <td><%# Eval("Total_SAI","{0:C2}")%></td>
                        <td class="FormViewCaseDetailsLabel">
                            (KPI) Payback:</td>
                        <td><%# Eval("PBP")%></td>
                    </tr>
                </table>
            </ItemTemplate>
            <HeaderStyle CssClass="HeaderStyle" />
        </asp:FormView>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Development Lead
Commented:
For second section, you can call a function with parameters as per your requirements
<%# CalculateValue(Eval("Field1") , Eval("Field2"))%>
then
define that method in code behind

function calculatevalue(byval fld1 as integer, byval fld2 as integer) as string

'' manipulate your parameters as per your requirements

return answer.tostring

end function


for third section you can simply bind session values in form view as

<%# session("str") %>

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial