c# - How to hide a hyperlink control inside gridview through code behind inside page load? -


I have a gridview on my web form. I have taken a hyperlink control inside the template field of Gridview. I want to show this hyperlink only to the site administrator I did this through the Gridview_RowDataBound property but instead of doing so, I want to hide this hyperlink inside the page load.

This is what I have done.

aspx page -

  & lt; ASP: GridView id = "GridView1" runat = "server" AutoGenerateColumns = "false" DataKeyNames = "ID" onrowdatabound = "GridView1_RowDataBound1" BorderStyle = "none" EnableModelValidation = "true" ShowHeader = "false" width = "1000 pixels" Gridline = "none" & gt; & Lt; Columns & gt; & Lt; ASP: TemplateField & gt; & Lt; ItemTemplate & gt; & Lt; asp: hyperlink id = "hyperlink 2" runat = "server" font-bold = "true" font-size = "small" ForeColor = "# FF3300" CommandName = "EDT" command agreement = "& lt;% # ((GridViewRow ) Container) .RowIndex%> "NavigateUrl = '& lt;% # Eval (" ID "," test1.aspx id = {0}? ")% & Gt; & Gt; HyLink & lt; / ASP: Hyperlink & gt; & Lt; / ItemTemplate & gt; & Lt; / ASP: TemplateField & gt; & Lt; / Column & gt; & Lt; / ASP: GridView & gt;   

CS page -

  Protected Zero Gridview1_RadataBound1 (Object Sender, GridVieworrent ARGS E) {if (E.RO.RowType == Data ControllerV Type.dataro) {if convert (session to ["log name"]) = "admin") {hyperlink hlnk = e. Cry. FIDCantrol ("hyperlink 2") as hyperlink; Hlnk.Visible = false; }}}   

How can I do this in page loads? Please guide.

Try this:

  foreach (GridViewRow row in GridView1.Rows ) {If (row.RowType == DataControlRowType.DataRow) {Hyperlink myHyperLink = row.FindControl ("HyperLink2") as a hyperlink; MyHyperLink.Visible = false; }}   

or:

 for  (int i = 0; i   

But make sure to force the data to suppress the data, get control inside it, otherwise it will not work.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -