ASP.NET GridView行可见或其他错误 [英] Asp.net gridview row visible or else not error

查看:52
本文介绍了ASP.NET GridView行可见或其他错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,程序员在这里遇到了一些问题.我的gridview是一个标签,如果它具有值,则一列将可见,但如果没有值,则该列将不可见.这是我的代码

Hello programmers, got a few problem here. Im my gridview is a label which is if it has a value the one column will be visible but if hasnt the the column will not be visible. Here is my code

Protected Sub grdCourse_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdCourse.RowDataBound
       Dim x As Integer = Session("X")
       If x = "1" Then
           If e.Row.RowType = DataControlRowType.DataRow Then
               Dim labelDID As Label = DirectCast(e.Row.FindControl("DisciplineCourseID"), Label)
               If labelDID.Text <> "" Then
                   grdCourse.Columns(6).Visible = True
               Else
                   grdCourse.Columns(6).Visible = False
               End If
           End If


现在,当gridview在行标签上检测到一个值时,出现错误原因,即使某些行标签没有值,该列也将可见.换句话说,如果它检测到标签具有值,则该列将可见.
我想要的是,行将被一一检查,如果labelDID为null,则Columns(6).Visible = False
先生,谢谢您的时间,对我的英语


Now Im getting an error cause when the gridview detect one value on a row label, the column will be visible even if some row label dont have value. In other term if it detects that the label has a value then the column will be visible.
All I want sir is the row will be check one by one and if the labelDID is null then Columns(6).Visible = False
Is it possible sir?Thanks for your time and sorry for my english

推荐答案

知道了.而不是使用column(i),我将其修改为这个
Got It. instead of using columns(i) I chage it to this one
Dim img As ImageButton = DirectCast(e.Row.FindControl("ImageDeleteCourse"), ImageButton)
               If labelDID.Text <> "" Then
                   img.Visible = True
               Else
                   img.Visible = False
               End If


但是还是要谢谢


But thanks anyway




根据我的理解,您的要求是,如果您至少有一个单元格包含数据..那么该列应该是可见的.否则是不可见的.

正确吗?

如果是这样,
1.获取一个会话变量.
2.将其初始化为false.
3.在您的行绑定中,
Hi,

As per my understanding, your requirement is if you have atleast one cell with data..then the column should be visible.Else invisible.

Is that correct?

If so,
1.Take a session variable.
2.Initialise it to false.
3.In your row bound ,
if the session variable is false then
  check the data of the label.
        if the data is present
            assign true to session variable.
         end if
 end if

 if sessionvariable is true then
  column.visible=true



希望这会有所帮助.



Hope this helps.


这篇关于ASP.NET GridView行可见或其他错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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