Click here to Skip to main content
16,004,587 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
VB
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

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
Posted
Updated 23-Jan-12 18:43pm
v2

Got It. instead of using columns(i) I chage it to this one
VB
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
 
Share this answer
 
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.
 
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