其实我有一个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 列具有空值或空白时,Out_Time 不应绑定,而应绑定另一列。
比方说
if(Out_Reason=null)
{
// then bind the column3 instead of Out_Time
}