How can I show and hide div tag inside GridView based on the value of the column?
For example if a column has a value of 1, then it should display a particular div and the hide the other
I tried this and it did not work
<asp:GridView ID="UsersGrid" runat="server" GridLines="None" AllowPaging="true" HeaderStyle-ForeColor="#224f6d" HeaderStyle-Font-Size="11pt" RowStyle-Font-Size="10pt" OnPageIndexChanging="OnPageIndexChanging"
AutoGenerateColumns="false" OnSelectedIndexChanged="OnSelectedIndexChanged" OnRowDataBound="OnRowDataBound" DataKeyNames="Name" PageSize="7" CssClass="table" Width="100%" HeaderStyle-HorizontalAlign="left" RowStyle-HorizontalAlign="Left">
<EmptyDataTemplate>
<div style="text-align: center; font-weight: 500; font-size: medium;">
<asp:Label ID="labelTemp" runat="server" Text="No Team Member"></asp:Label>
</div>
</EmptyDataTemplate>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="Checksuspend" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="Organization" HeaderStyle-Font-Bold="false" />
<asp:BoundField DataField="email" HeaderText="Email" ReadOnly="true" HeaderStyle-Font-Bold="false" />
<asp:BoundField DataField="CreatedDate" HeaderText="Date Joined" ReadOnly="true" HeaderStyle-Font-Bold="false" />
<asp:BoundField DataField="Suspend" HeaderText="Action" ReadOnly="true" HeaderStyle-Font-Bold="false" />
<asp:TemplateField HeaderText="Status" HeaderStyle-Font-Bold="false">
<ItemTemplate>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<div class="badge badge-pill badge-success" runat="server" id="active" style="font-weight: 500; font-size: 9pt;">Active</div>
<div class="badge badge-pill badge-info" runat="server" id="blocked" style="font-weight: 500; font-size: 9pt;">Suspended</div>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[3].Visible = false;
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 1; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(UsersGrid, "Select$" + e.Row.RowIndex);
e.Row.Cells[i].Style.Add("cursor", "pointer");
e.Row.Cells[i].ToolTip = "View Details.";
e.Row.Cells[3].Visible = false;
Suspend = e.Row.Cells[4].Text;
if (Suspend = "1")
{
Blocked.Visible = true;
active.Visible = false;
}
else
{
Blocked.Visible = false;
active.Visible = true;
}
}
}
}
Don't know why I am getting this error (the name does not exist in the current context), even after I used runat="server" in the div tags.
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[3].Text == "1")
{
Blocked.Visible = true;
active.Visible = false;
}
else
{
Blocked.Visible = false;
active.Visible = true;
}
}