i have a dropdown list according to whose selected value i have to show and hide a column in gridview. i am able to do this but there is a problem sometimes the code works fine and the column gets hidden other times it is shown.
here is my code sample
<pre lang="c#"><pre lang="c#">
Public Function dropoptions1() As String
Dim pending As String
pending = "select distinct a.deptcode,b.transid,a.desgid,a.empdesignation,a.empno,a.name ,a.deptcode,to_char(b.dtleavefrom,'dd-Mon-yyyy') as dtleavefrom ,to_char(b.dtleaveto,'dd-Mon-yyyy') as dtleaveto,to_char(b.keyedon,'dd-Mon-yyyy') as applydate,c.desp,DECODE(b.dtleaveto -b.dtleavefrom,0,1,b.dtleaveto -b.dtleavefrom) dAYS,d.statusdesc from tt.employees a join dilpreet.leavedetails b on a.empno=b.empid join ranu.leavemaster c on b.leaveid=c.leaveid join dilpreet.leavestatus d on b.status=d.statusid "
If source2.SelectedValue = 1 Then
Gridchild.Columns(1).Visible = True
pending &= "where (b.status='P' or b.status='PR' or b.status='AP')"
pending &= " and b.dtleavefrom LIKE '%" & dpcalander.Text.ToUpper() & "%'"
Dim selected As String = ""
Dim sep As String = ""
Dim sep1 As String = ""
For Each node As RadTreeNode In treedetails.Nodes
If node.Checked = True Then
selected += sep + node.Value
sep = ","
End If
Next
pending &= " and a.zbaid in (" & selected & ")"
Dim selected1 As String = ""
For Each node As RadTreeNode In treedetails.Nodes
If node.Checked = True Then
For Each subnode As RadTreeNode In node.Nodes
If subnode.Checked Then
selected1 += sep1 + subnode.Value
sep1 = ","
End If
Next
End If
Next
pending &= " and a.deptcode in (" & selected1 & ")"
'If DropDownList1.SelectedValue = 1 Then
' pending &= "leave"
'ElseIf DropDownList1.SelectedValue = 2 Then
' pending &= "gatepass"
'End If
End If
Return pending
End Function
Public Function dropoptions2() As String
Dim cancelled As String
cancelled = "select distinct a.deptcode,b.transid,a.desgid,a.empdesignation,a.empno,a.name ,a.deptcode,to_char(b.dtleavefrom,'dd-Mon-yyyy') as dtleavefrom ,to_char(b.dtleaveto,'dd-Mon-yyyy') as dtleaveto,to_char(b.keyedon,'dd-Mon-yyyy') as applydate,c.desp,DECODE(b.dtleaveto -b.dtleavefrom,0,1,b.dtleaveto -b.dtleavefrom) dAYS,d.statusdesc from tt.employees a join dilpreet.leavedetails b on a.empno=b.empid join ranu.leavemaster c on b.leaveid=c.leaveid join dilpreet.leavestatus d on b.status=d.statusid"
If source2.SelectedValue = 2 Then
Gridchild.Columns(0).Visible = True
cancelled &= " where (b.status='C') "
cancelled &= " and b.dtleavefrom LIKE '%" & dpcalander.Text.ToUpper() & "%'"
Dim selected As String = ""
Dim sep As String = ""
Dim sep1 As String = ""
For Each node As RadTreeNode In treedetails.Nodes
If node.Checked = True Then
selected += sep + node.Value
sep = ","
End If
Next
cancelled &= " and a.zbaid in (" & selected & ")"
Dim selected1 As String = ""
For Each node As RadTreeNode In treedetails.Nodes
If node.Checked = True Then
For Each subnode As RadTreeNode In node.Nodes
If subnode.Checked Then
selected1 += sep1 + subnode.Value
sep1 = ","
End If
Next
End If
Next
cancelled &= " and a.deptcode in (" & selected1 & ")"
'If DropDownList1.SelectedValue = 1 Then
' cancelled &= "leave"
'ElseIf DropDownList1.SelectedValue = 2 Then
' cancelled &= "gatepass"
'End If
End If
Return cancelled
End Function
by default i have set the template fields visible=false