実際、私はGridviewを持っています。条件付きでバインドする必要があります。以下のコードを参照してください
<asp:GridView ID="GVReport" runat="server" AutoGenerateColumns="False"
EnableModelValidation="True" Width="770px"
DataKeyNames="User_Id"
CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True"
onpageindexchanging="GVReport_PageIndexChanging"
onrowdatabound="GVReport_RowDataBound" ShowFooter="True" PageSize="31">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<asp:Label ID="Label1" runat="server"
Text='<%# Convert.ToDateTime(Eval("Login_Date")).ToString("dd/MM/yyyy") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="In Time">
<ItemTemplate>
<asp:Label ID="Label2" runat="server"
Text='<%# String.Format("{0:t}", Eval("In_Time")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Out Time">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%#String.Format("{0:t}", Eval("Out_Time")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="HRs" DataField="Hrs">
<FooterStyle HorizontalAlign="Left" />
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="Comments" HeaderText="Late Reason" />
<asp:BoundField DataField="Out_Reason" HeaderText="Out Reason" />
<asp:BoundField DataField="Attendance_Status" HeaderText="Status" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White"
HorizontalAlign="Left" />
<PagerStyle BackColor="#2461BF" ForeColor="White"
HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
以下のように私のストアドプロシージャ
select
User_Id, Login_Date, Week_Day,
In_Time, Out_Time, Late_Reason, Out_Reason,
Attendance_Status
from
mtblAttendance
where
Login_Date between @Date1 and @Date2
and User_Id = @User_Id
order by
Login_Date
私の条件は、Out_Reason 列に null 値または空白がある場合、Out_Time をバインドしないで、代わりに別の列をそこにバインドする必要があるということです。
まあ言ってみれば
if(Out_Reason=null)
{
// then bind the column3 instead of Out_Time
}