Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hi i want set attribute element in gridview.
i have a gridview.
in to grid view have UpdatePanel.
in to updatepanel have div tag.
i set div : runat="server"
i want in code-behind set : mydiv.visible=false;
how i can do it ?
Posted
Comments
bowlturner 8-Jul-14 14:04pm    
try pasting in the code with the Improve question link. We could see what you did and need to do.
mor kan 8-Jul-14 14:30pm    
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
Width="858px" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" >

<alternatingrowstyle backcolor="ActiveCaption">

<columns>

<asp:TemplateField>

<itemtemplate>

<asp:UpdatePanel ID="up1" runat="server">
<contenttemplate>
<div id="Wrapper">

<div id="ColumnRight">
<div id="divContent">
<div style="width: 541px; float: left; height: 420px auto; background-color: White;">
<asp:Label runat="server" ID="lblIDSubPost" CssClass="lblIDSubPost" Text='<%# Eval("IDSubPost") %>'>
<br />
<asp:Label ID="lblContent" CssClass="lblContent" runat="server" Text='<%# Eval("TextPost") %>'>
</div>
</div>

</div>



<div id="ColumnLeft">

<img runat="server" alt="" id="imgAvater" class="imgAvater" src="~/Images/fantasicD2/1.png" />
<br />


<asp:Label runat="server" ID="lblUserName" Text='<%# Eval("UserNameSender") %>' CssClass="lblUserName">


<br />


<div id="divName">
<div style="position: static; float: right;">
<asp:Label runat="server" ID="txtName" Text='<%# Eval("Name") %>' CssClass="txtName">
<asp:Label runat="server" ID="lblName" Text=": نام" CssClass="lblName">
<img runat="server" id="imgName" src="~/Images/fantasicD3/Name.png" class="imgName" />
</div>
</div>

<br />

<div id="divFamily">
<div style="position: static; margin-top: 5px; float: right;">
<asp:Label runat="server" ID="txtFamily" Text='<%# Eval("Family") %>' CssClass="txtFamily">
<asp:Label runat="server" ID="lblFamily" Text=": نام خانوادگی" CssClass="lblFamily">

<img runat="server" id="img1" src="~/Images/fantasicD3/Family.png" class="imgFamily" />
</div>
</div>
<br />
<div id="divLocationLive">
<div style="position: static; margin-top: 5px; float: right;">
<asp:Label runat="server" ID="txtLocatiocnLive" Text='<%# Eval("State") %>' CssClass="txtFamily">
<asp:Label runat="server" ID="lblLocationLive" Text=":محل سکونت " CssClass="lblFamily">

<img runat="server" id="imgLocationLive" src="~/Images/fantasicD3/LocationLive.png" class="imgFamily" />
</div>
</div>
<br />
<

Make sure you div has this property "runat="server" and an id that can be referenced from your code behind.
XML
<div  runat="server" id="divName"></div>


Then, from code behind:

C#
divName.Visible = false;
 
Share this answer
 
v2
Comments
mor kan 8-Jul-14 14:27pm    
in page load not exist my divname
i think solved my problem but ...
i test below code ,this find contentplaceholder but not find my element.
C#
ContentPlaceHolder mpContentPlaceHolder;

           mpContentPlaceHolder = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder2");
           if (mpContentPlaceHolder != null)
           {

               Label mpLabel = (Label)Master.FindControl("IdTopic");
               if (mpLabel != null)
               {
                   ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "ShowAlert();", true);
               }

           }

and insert
ASP.NET
<%@ MasterType   virtualPath="~/level2.Master"%>

but not work.
my refrence code is : link
i use master page .
my code is into contetntplaceholder.
in content place holder have gridview.
my code is:
ASP.NET
<asp:GridView ID="showPostrRGridView" runat="server" AutoGenerateColumns="false" Width="858px" OnSelectedIndexChanged="showPostrRGridView_SelectedIndexChanged" >



       <Columns>

           <asp:TemplateField>

               <ItemTemplate>

                   <div id="BorderTopic" class="BorderTopic">
                       <div id="TopicView1" class="TopicView">
                           <asp:Label ID="IdTopic" runat="server" Text='<%# Eval("IDTopic") %>' Visible="false"></asp:Label>
                           <table style="width: 100%; height: 100%;">
                               <tr>
                                   <td style="width: 4%; height: 100%;"></td>
                                   <td style="width: 52%; height: 100%; border-left-color: black; border-left-style: solid; border-left-width: 0.5px;">
                                       <div>
                                           <table style="width: 100%; height: 100%;">
                                               <tr style="width: 100%; height: 25%;">
                                                   <td>
                                                       <asp:LinkButton ID="linkToPost" Text='<%# Eval("titleTopic") %>' Font-Size="Large" Font-Names="b yekan" runat="server" ForeColor="#c6c574" OnClick="linkToPost_Click"></asp:LinkButton></td>
                                               </tr>
                                               <tr style="width: 100%; height: 25%;">
                                                   <td>
                                                       <asp:Label runat="server" Text='<%# Eval("Description") %>' Font-Size="Small" Font-Names="b yekan"></asp:Label></td>
                                               </tr>
                                           </table>
                                       </div>

                                   </td>
                                   <td style="width: 40%; height: 100%;">
                                       <div>
                                           <table style="width: 100%; height: 100%;">
                                               <tr>
                                                   <td style="width: 50%; height: 100%;">
                                                       <div>
                                                           <table style="width: 100%; height: 50%;">
                                                               <tr>
                                                                   <td align="center">
                                                                       <asp:Label runat="server" Text="تعداد مبحث های تاپیک" ID="lblMabhas" Font-Size="Large" Font-Names="b yekan" ForeColor="#c6c574"></asp:Label>
                                                                   </td>
                                                               </tr>
                                                               <tr>
                                                                   <td align="center" >
                                                                       <asp:Label runat="server" Text='<%# Eval("NumOfPost") %>' Font-Size="Small" Font-Names="b yekan"></asp:Label>
                                                                   </td>
                                                               </tr>
                                                           </table>
                                                       </div>
                                                   </td>
                                                   <td style="width: 50%; height: 100%;">
                                                       <div>
                                                           <table style="width: 100%; height: 50%;">
                                                               <tr>
                                                                   <td align="center">
                                                                       <asp:Label runat="server" Text=" ارسال آخرین مطلب" Font-Size="Large" Font-Names="b yekan" ForeColor="#c6c574"></asp:Label>
                                                                   </td>
                                                               </tr>
                                                               <tr>
                                                                   <td align="center">
                                                                       <asp:Label runat="server" Text='<%# Eval("DatePost") %>' Font-Size="Small" Font-Names="b yekan"></asp:Label>
                                                                   </td>
                                                               </tr>
                                                           </table>
                                                       </div>
                                                   </td>

                                               </tr>
                                           </table>
                                       </div>
                                   </td>
                                   <td style="width: 4%; height: 100%;"></td>

                               </tr>
                           </table>
                       </div>

                   </div>
               </ItemTemplate>
           </asp:TemplateField>
       </Columns>

   </asp:GridView>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900