我有一个用户控件,我想在rowdatabound上分配值:
<asp:TemplateField HeaderText="Delivery Date">
<ItemTemplate>
<asp:Label ID="lblDeliveryDate" CssClass="NormalText" runat="server" Text='<%# Eval("DDateTime") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<uc1:WUCDateHourMin ID="WUCDeliverydate" runat="server" />
</EditItemTemplate>
<ItemStyle Width="10%" />
</asp:TemplateField>
我将rowdatabound上的edittemplate的值绑定为:
If e.Row.RowState = DataControlRowState.Edit Then
CType(e.Row.FindControl("WUCDeliverydate"), WUCDateHourMin).BindFromDateTime(gc.GetDate(e.Row.DataItem("EDateTime")), 0, 0)
End If
但它仅绑定备用行(奇数行,第1,第3,第5)。我不知道发生了什么。
请帮帮我。
答案 0 :(得分:0)
我完成了如下操作:
If (e.Row.RowState And DataControlRowState.Edit) > 0 Then
If IsDBNull(e.Row.DataItem("DDateTime")) Then
CType(e.Row.FindControl("WUCDeliverydate"), WUCDateHourMin).BindFromDateTime(gc.GetDate(Now()), 0, 0)
Else
CType(e.Row.FindControl("WUCDeliverydate"), WUCDateHourMin).BindFromDateTime(gc.GetDate(e.Row.DataItem("EDateTime")), 0, 0)
End If
End If