C# 隐藏gridview中的某一列(在前台不显示),以及如何获取隐藏列的地址

1、在前台添加OnRowDataBound="gvShow_RowDataBound" 事件

<CimesUI:CimesGridView Width="60%" style="margin:0 auto;" ID="gvShow" runat="server" AutoGenerateColumns="False"   OnRowDataBound="gvShow_RowDataBound"
                  allowpaging="true" pagesize="30">

 

 

2、在后台的gvShow_RowDataBound设置要隐藏的列

复制代码
  protected void gvShow_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                // 隐藏表头的列
                e.Row.Cells[3].Visible = false; // 根据索引隐藏列
            }
            else if (e.Row.RowType == DataControlRowType.DataRow)
            {
                // 隐藏数据行的列
                e.Row.Cells[3].Visible = false; // 根据索引隐藏列
            }
        }
复制代码

 

3、获取隐藏列的值,在RowDataBound里面添加如下代码

复制代码
    后台代码
protected void gvShow_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header) { // 隐藏表头的列 e.Row.Cells[3].Visible = false; // 根据索引隐藏列 } else if (e.Row.RowType == DataControlRowType.DataRow) {
            //这里的
Reliability_Picture_SID就是隐藏的列,需根据实际情况调整
            string reliabilityPictureSid = DataBinder.Eval(e.Row.DataItem, "Reliability_Picture_SID").ToString(); 
            // 创建一个隐藏字段并将Reliability_Picture_SID的值赋给它
            HiddenField hiddenField = new HiddenField();
            hiddenField.Value
= reliabilityPictureSid; // 将隐藏字段添加到行中
            e.Row.Cells[0].Controls.Add(hiddenField);   
            // 隐藏数据行的列   
            e.Row.Cells[3].Visible = false;
      }
    }
前台代码
复制代码
 <CimesUI:CimesGridView ID="gvColse" runat="server" AutoGenerateColumns="False" CssClass="centered-gridview"
                                            DataKeyNames="Reliability_Picture_SID" OnRowDeleting="gvColse_RowDeleting" OnRowDataBound="gvColse_RowDataBound">
                                            <Columns>
                                                <asp:CommandField HeaderText="操作" ShowDeleteButton="True">
                                                    <ItemStyle HorizontalAlign="Center" />
                                                </asp:CommandField>
                                                <asp:TemplateField HeaderText="操作" HeaderStyle-Width="50px">
                                                    <ItemTemplate>
                                                        <a href="javascript:;" onclick="return DownLoadCloseFile(this)">下载</a>
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:BoundField DataField="Reliability_Picture_SID" HeaderText="Reliability_Picture_SID" />
                                                <asp:BoundField DataField="AbnormalCause" HeaderText="异常分类" />
                                                <asp:BoundField DataField="AbnormalDevice" HeaderText="异常制程" />
                                                <asp:BoundField DataField="AbnormalProcess" HeaderText="异常器件" />
                                                <asp:BoundField DataField="CloseReasonDescr" HeaderText="具体原因描述" />
                                                <asp:BoundField DataField="fileName" HeaderText="分析报告" />
                                            </Columns>
                                            <EmptyDataTemplate>
                                                没有附档存在!
                                            </EmptyDataTemplate>
                                        </CimesUI:CimesGridView>

1
2
3
4
5
6
7
8
9
10
11
12
13
function DownLoadCloseFile(UserLink) {
            console.log("1222222222223");
            var row = UserLink.parentNode.parentNode;
            console.log(row);
            var id = row.cells[1].innerHTML;
            console.log(id);
              let method = "CloseFile"
             var hiddenField = row.querySelector('input[type="hidden"]');
    if (hiddenField) {
        // 获取隐藏字段的值,即Reliability_Picture_SID
        var reliabilityPictureSid = hiddenField.value;
}
}

  

 
复制代码

 

 
复制代码

 

posted on   写个笔记  阅读(176)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示