首页 > Web开发 > 详细

asp.net的gridview中datarowbound事件中绑定数据与其它不可视控件数据的获取

时间:2020-02-23 19:33:43      阅读:76      评论:0      收藏:0      [点我收藏+]

 //测试

                       // e.Row.Cells[1].Text += " " + zymc;某bound绑定列如果被隐藏,则不能获取它的文本信息,也没有错误提示,

                        //可以采用在模板列用label的text属性记录,把该label的visible=false

                       // e.Row.Cells[1].Text += " " + zymc;

Gridview的datarowbound事件,某列为绑定列,属性visble=false时,不能获取其数据信息,也不出错。可以采用改为隐藏属性的模板列,修改其中的部分设计代码,或者专门建立某模板列,在模板列中加入隐藏的label控件,用text属性保存字段内容,这些内容能够被获取

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CssClass="grid" DataKeyNames="ID"  PageSize="20" style="text-align: center" Width="100%" BackColor="AliceBlue" OnRowDataBound="GridView1_RowDataBound" OnRowCommand="GridView1_RowCommand" Font-Size="Small" Caption="推荐用谷歌浏览器;高分优先学校用蓝色显示">

                                     <AlternatingRowStyle CssClass="alternating" />

                                     <Columns>

                                         <asp:BoundField DataField="dm" HeaderText="代号">

                                        

                                         <ItemStyle Width="8%" HorizontalAlign="Left" />

                                        

                                         </asp:BoundField>

                                         <asp:BoundField DataField="xxmc" HeaderText="学校名称">

                                        

                                         <ItemStyle Width="32%" HorizontalAlign="Left" />

                                        

                                         </asp:BoundField>

                                         <asp:TemplateField HeaderText="专业名称" Visible="False">

                                             

                                             <ItemTemplate>

                                                 <asp:Label ID="lbl_zymc" runat="server" Text=‘<%# Eval("zymc") %>‘></asp:Label>

                                             </ItemTemplate>

                                         </asp:TemplateField>

                                         <asp:BoundField DataField="pc" HeaderText="批次或其它">

                                        

                                         <ItemStyle Width="23%" HorizontalAlign="Left" />

                                        

                                         </asp:BoundField>

                                         <asp:BoundField DataField="lqfs" HeaderText="录取分">

                                      

                                         <ItemStyle Width="8%" HorizontalAlign="Left" />

                                      

                                         </asp:BoundField>

                                         <asp:BoundField DataField="pjf" HeaderText="平均分">

                                        

                                         <ItemStyle Width="8%" HorizontalAlign="Left" />

                                        

                                         </asp:BoundField>

                                         <asp:TemplateField>

                                             <ItemTemplate>

                                                  <asp:Button ID="btn_zy_yp" runat="server"

                                                     CommandArgument=‘<%# Eval("ID") %>‘

                                                    CommandName="gly_zy_xx" CssClass="btn" Text="专业" Width="30" Visible="true" />

                                                

                                             </ItemTemplate>

                                         </asp:TemplateField>

                                         <asp:TemplateField HeaderText="确认">

                                              <ItemTemplate>

                                                   <asp:CheckBox id="cbSelect" runat="server"   ToolTip=‘<%# Eval("ID") %>‘

                                                   OnCheckedChanged="cbSelect_CheckedChanged" AutoPostBack="true" />

                                                 

                                               </ItemTemplate>

                                            

                                              <ItemStyle Width="21%" HorizontalAlign="Left" />

                                            

                                         </asp:TemplateField>

                                         <asp:TemplateField HeaderText="特征" Visible="False">

                                            

                                             <ItemTemplate>

                                                 <asp:Label ID="lbl_tz" runat="server" Text=‘<%# Eval("tz") %>‘></asp:Label>

                                             </ItemTemplate>

                                         </asp:TemplateField>

                                     </Columns>

                                     <HeaderStyle CssClass="header" />

                                     <RowStyle CssClass="row" />

                                     <SelectedRowStyle CssClass="selectrow " />

                                 </asp:GridView>

后台代码:

 string dm = e.Row.Cells[0].Text.Trim();//代码

                    string xxmc = e.Row.Cells[1].Text.Trim();//学校名称

                    string xxpc = e.Row.Cells[4].Text.Trim();//学校批次

                    //再用查询语句降低读取效率

                    string zymc = ((Label)e.Row.FindControl("lbl_zymc")).Text.Trim();//专业名称

                    string tz = ((Label)e.Row.FindControl("lbl_tz")).Text.Trim();//学校特征,是否包含高分优先

                    if (zymc!=string.Empty)//有专业名称

                    {

                        Button btn_sdzy = e.Row.FindControl("btn_zy_yp") as Button;

                        btn_sdzy.Visible = true;

                        //测试

                       // e.Row.Cells[1].Text += " " + zymc;某bound绑定列如果被隐藏,则不能获取它的文本信息,也没有错误提示,

                        //可以采用在模板列用label的text属性记录,把该label的visible=false

                       // e.Row.Cells[1].Text += " " + zymc;

                    }

                    else

                    {

                        Button btn_sdzy = e.Row.FindControl("btn_zy_yp") as Button;

                        btn_sdzy.Visible = false;

                    }

asp.net的gridview中datarowbound事件中绑定数据与其它不可视控件数据的获取

原文:https://www.cnblogs.com/zrprj/p/12353129.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!