访问gridview中的div [英] access to div in gridview

查看:81
本文介绍了访问gridview中的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
i想要在gridview中设置属性元素。

i有一个gridview。

到网格视图中有UpdatePanel。

在updatepanel中有div标签。

i set div:runat =server

i想要代码隐藏设置:mydiv.visible = false;

我怎么做?

解决方案

确保div有这个属性runat =server一个id 可以从后面的代码中引用。

 <   div       runat   =  server    id   =  divName >  <   / div  >  





然后,从后面的代码:



 divName.Visible =  false ; 


我认为解决了我的问题,但是......

i test下面的代码,这个找到contentplaceholder但找不到我的元素。

 ContentPlaceHolder mpContentPlaceHolder; 

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

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

}



并插入

 <%@     MasterType         virtualPath   = 〜/ level2.Master %>  



但没有工作。

我的参考代码是:链接

i use母版页。

我的代码进入了contetntplaceholder。
内容占位符
有gridview。

我的代码是:

 <   asp:GridView     ID   =  showPostrRGridView    runat   =  server    AutoGenerateColumns   =  false   宽度  =  858px    OnSelectedIndexChanged   =  showPostrRGridView_SelectedIndexChanged   >  



< >

< asp:TemplateField >

< ItemTemplate >

< div id = BorderTopic class = BorderTopic > ;
< div id = TopicView1 class = TopicView >
< asp:Label ID = IdTopic runat = server 文字 =' <% #Eval( IDTopic)%>' 可见 = false > < / asp:标签 >
< table style = width:100%;高度:100%; >
< tr >
< td style = width:4%;高度:100%; > < / td >
< td style = 宽度:52%;身高:100%; border-left-color:black; border-left-style:solid; border-left-width:0.5px; >
< div >
< style = width:100%;高度:100%; >
< tr style = width:100%;高度:25%; >
< td >
< asp:LinkBut​​ton ID = linkToPost 正文 =' <% #Eval( titleTopic)%>' 字体大小 = 字体名称 = b yekan runat = server ForeColor < span class =code-keyword> = #c6c574 OnClick = linkToPost_Click > < / asp:LinkBut​​ton > < / td >
< / tr >
< tr style = width:100%;高度:25%; >
< td >
< asp:标签 runat = 服务器 正文 =' <% #Eval( 描述)%>' 字体大小 = 字体名称 = b yekan > < / asp:标签 > < / td >
< / tr >
< / table >
< / div >

< / td >
< td style = width:40%;高度:100%; >
< div >
< style = width:100%;高度:100%; >
< tr >
< td style = width:50%;高度:100%; >
< div >
< style = width:100%;高度:50%; >
< tr >
< td align = center >
< asp:标签 runat = server 文字 = تعدادمبحثهایتاپیک ID = lblMabhas 字体大小 = 字体名称 = b yekan ForeColor = #c6c574 > < / asp:标签 >
< / td >
< / tr >
< tr >
< td align = center >
< asp:Label runat = < span class =code-keyword> server
文本 =' <% #Eval( NumOfPost)%>' 字体大小 = 字体名称 = b yekan > < / asp:标签 >
< / td >
< / tr >
< / table >
< / div >
< / td >
< td style = 宽度:50%;高度:100%; >
< div >
< style = width:100%;高度:50%; >
< tr >
< td align = center >
< asp:标签 runat = server 文字 = 字体大小 = 字体名称 = b yekan ForeColor = #c6c574 > < / asp:标签 >
< / td >
< / tr >
< tr >
< td align = center >
< asp:标签 runat = 服务器 文本 =' <% #Eval( DatePost)%>' 字体大小 = < span class =code-keyword>小
字体名称 = b yekan > < / asp:标签 >
< span class =code-keyword>< / td >
< / tr >
< / table >
< / div >
< / td >

< / tr >
< / table >
< / div >
< / td >
< td 样式 = 宽度:4% ;高度:100%; > < / td >

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

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

< / asp:GridView >


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 ?

解决方案

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

<div  runat="server" id="divName"></div>



Then, from code behind:

divName.Visible = false;


i think solved my problem but ...
i test below code ,this find contentplaceholder but not find my element.

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

<%@ 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: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>


这篇关于访问gridview中的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆