0
Answer

Show the `TemplateField` where Cookies condition

Hi there, I hope your appreciated help.
First of all I must say that I am a newbie when it comes to net language.

This is my problem:

I need show the `TemplateField` in `GridView` of my net page only when the Request.Cookies["MyCookie"] is not 'null' and have `1` value.

I follow this approch: would be to give a HeaderText for TemplateField, say Image, and then find using that and try this code.

I don't have error but the `TemplateField` Image is always visible.

Can you hep me?

Can you help me? thank you in advance.
Your help would be very appreciated


public void Page_Load (Object sender, EventArgs e)
{
if (Request.Cookies["MyCookie"] != null)
{
string fld = Request.Cookies["MyCookie"].Value;
Response.Write("Hello ...<br>");
Response.Write(fld + "<br>");
}

}


protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{

(
(DataControlField)GridView1.Columns
.Cast<DataControlField>()
.Where(fld => fld.HeaderText == "Image")
.SingleOrDefault()
).Visible = false;
}



<asp:TemplateField HeaderText="Image">

<ItemTemplate>
<asp:ImageButton ID="ImageButton1" CommandName="Edit" Runat="Server"
ImageUrl="/Images/edit.gif" ToolTip="edit"
OnClientClick="return confirm('Confirm?.');" />
</ItemTemplate>

<EditItemTemplate>
<asp:ImageButton ID="ImageButton2" CommandName="Update" Runat="Server"
ImageUrl="/Images/update.gif" ToolTip="update"
OnClientClick="return confirm('Confirm?.');" />

<asp:ImageButton ID="ImageButton3" CommandName="Delete" Runat="Server"
ImageUrl="/Images/delete.gif" ToolTip="delete"
OnClientClick="return confirm('Confirm?.');" />
</EditItemTemplate>

</asp:TemplateField>
Next Recommended Forum