GridViewの0件表示時
GridViewにBindするDataSourceのデータが0件時に、追加だけとりあえず行いたい。という要件があったので、EmptyDataTemplateを使ってみた。
自動的に表示してくれるが、通常データが存在するときと同じイメージにするべく、このTemplate上に、Tableタグを書くことに。若干面倒だけど、まぁよし。
<EmptyDataTemplate> <table cellspacing="0" cellpadding="4" rules="all" border="1" style="color:#333333;border-collapse:collapse;"> <tr style="color:White;background-color:#507CD1;font-weight:bold;"> <th style="height: 12px">製品ID</th> <th style="height: 12px">製品名</th> <th style="height: 12px">部品</th> <th style="height: 12px">型番</th> <th style="height: 12px">更新日</th> </tr> <tr style="background-color:#EFF3FB;"> <td><asp:TextBox ID="txtISeihinId" runat="server"></asp:TextBox></td> <td><asp:TextBox ID="txtISeihinMei" runat="server"></asp:TextBox></td> <td><asp:TextBox ID="txtIBuhin" runat="server"></asp:TextBox></td> <td><asp:TextBox ID="txtIKataban" runat="server"></asp:TextBox></td> <td><asp:Button ID="btnAdd" runat="server" OnClick="btnAdd_Click" Text="追加" /></td> </tr> </table> </EmptyDataTemplate>