ASP.NET WebフォームにEmptyDataTemplateがあり、ユーザーはデータベースにレコードを追加できます。ユーザーの権限に応じて、このEmptyDataTemplateは、データが見つからない場合に表示され、非表示にする必要があります(私はこれが機能しています)。 たとえば、ユーザーには読み取り専用アクセス権があります。特定の条件を検索すると、EmptyDataTemplateが表示されない結果は表示されません。ただし、条件を検索してデータがある場合、データはヘッダーなしで表示されます。EmptyDataTemplateを非表示にしますが、ヘッダーを表示したままにします。
誰かがなぜこのようなことが起こっているのか、周囲に道があるのか説明するのに役立つことができますか?
ヘッダーはTemplateFieldsのHeaderTextです。
私はそれが一般的なトリックだと思っています。 ご協力いただきありがとうございます! 私は表示したいTemplateFieldsのHeaderTextです。空のDataTemplateには検索条件に一致するデータの列を表示しないので、表示しません。
編集:
(iは1列のみを示してきたが、マークアップはそれらのすべてについて同じである)ヘッダテキストのマークアップに protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Control control = null;
control = GridView1.Controls[0].Controls[0];
if (userManagement.getMIFReadWriteAccess() == "Read")
{
control.Visible = false;
Export_All.Visible = true;
}
else if (userManagement.getMIFReadWriteAccess() == "Write")
{
control.Visible = true;
Export_All.Visible = true;
}
}
:要求されたコードがEmptyDataTemplateを隠すため を添加
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="lbl_Index" runat="server" Text='<%#Eval("id") %>'></asp:Label>
<asp:Label ID="lbl_ID" runat="server" Text="" Visible="false"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
EmptyDataTemplate:試用後
<EmptyDataTemplate>
<div id="emptyData" runat="server">
<tr>
<th></th>
<th>Serial Number</th>
<th>Comments</th>
<th>Review Date</th>
<th>Approved By</th>
</tr>
<tr>
<td>
<asp:Button runat="server" ID="btInsert" Text="In" OnClick="Add" CommandName="EmptyDataTemplate" Class="Button" OnClientClick="return confirm('You are about to confirm this action. Please confirm this action by clicking OK. If you do not wish to do this, please select Cancel.');" />
<br />
<asp:Button runat="server" ID="btInsertOut" Text="Out" OnClick="AddOut" CommandName="EmptyDataTemplate" Class="Button" OnClientClick="return confirm('You are about to confirm this action. Please confirm this action by clicking OK. If you do not wish to do this, please select Cancel.');" />
</td>
<td>
<asp:TextBox runat="server" ID="tb_Serial_Number" CssClass="text"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="tb_comments" Width="100%" MaxLength="50" runat="server" placeholder="max 50 characters"/>
</td>
<td>
<asp:TextBox ID="tb_reviewDate" runat="server" DataFormatString="{0:dd/mm/yyyy}" Text='<%#Eval("review_by") %>'></asp:TextBox>
</td>
<td><asp:DropDownList ID="tb_approved_by" runat="server">
</asp:DropDownList> </td>
</tr>
</div>
</EmptyDataTemplate>
あなたのコード – Raghavendra
こんにちはを共有することができ、私は今、それを追加しました。ありがとう – akb29