Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have beed lookin arrounf=d for sometime
i need to hide column in a datatable loaded from session
i tried mapping.hidden but did nt work
i already add them to session hidden but they appear in page 2
may any help pls

this is page 2 page load
VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       Response.Cache.SetCacheability(HttpCacheability.NoCache)
       setMenu()
       Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache)
       Response.Cache.SetNoStore()
       lbldte.Text = DateAndTime.Now.ToShortDateString
       If Page.PreviousPage IsNot Nothing Then
           Dim GridView1 As GridView = DirectCast(Page.PreviousPage.FindControl("GridView1"), GridView)

       End If
       If Session("ProductsTable") IsNot Nothing Then
           dt = DirectCast(Session("ProductsTable"), DataTable)

           GridView1.DataSource = dt
           GridView1.DataBind()

       End If

       If Not IsPostBack Then
           'check if the webpage is loaded for the first time.
           'Saves the Previous page url in ViewState
           ViewState("PreviousPage") = Request.UrlReferrer
       End If
   End Sub
Posted

C#
dt.Columns.Remove("columnName");
dt.Columns.RemoveAt(columnIndex);


Try this and see.
 
Share this answer
 
the remove will delete the value inside
but i wana keep it as i insert it to database on button click
 
Share this answer
 
Comments
kumar2413 20-May-13 4:27am    
try this then
"dt.Columns[0].Visible= false;"
should i try this in page 2 after loading session
or page 1 before adding to session
as in page 1 i already have them hidden , but they appear in page 2
 
Share this answer
 
Comments
kumar2413 20-May-13 4:31am    
Then put it in page 2 n try.
shery_l 20-May-13 4:32am    
that is what i get

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30456: 'Visible' is not a member of 'System.Data.DataColumn'.

Source Error:


Line 37:
Line 38: End If
Line 39: dt.Columns(0).Visible = False
Line 40: If Not IsPostBack Then
Line 41: 'check if the webpage is loaded for the first time.
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30456: 'Visible' is not a member of 'System.Data.DataColumn'.

Source Error:


Line 37:
Line 38: End If
Line 39: dt.Columns(0).Visible = False
Line 40: If Not IsPostBack Then
Line 41: 'check if the webpage is loaded for the first time.
 
Share this answer
 
Comments
kumar2413 20-May-13 4:34am    
try to put in the session first and check and then try to put inside IsPagePostBack.
shery_l 20-May-13 4:37am    
not working!!!!
kumar2413 20-May-13 4:38am    
Tried both way?
yes
i did
this code at page 1 submit button

Protected Sub btnGetData_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGetData.Click
Dim strEMPPRJCDE As String
Dim strEMPBRN As String
Dim strVSTDTE As String
Dim strBRNCDE As String
Dim strPRJCDE7 As String
Dim strEMPAGE As String
Dim strEMPSRL As String
Dim strRQSTSRC As String
Dim strUPDUSR As String
Dim strEMPBRTDAT As String

dt.Columns.Add("Serial no.", GetType(Integer))
dt.Columns.Add("Employee code", GetType(String))
dt.Columns.Add("Employee Name", GetType(String))
dt.Columns.Add("Telephone", GetType(String))
dt.Columns.Add("Branch(job)", GetType(String))
dt.Columns.Add("General Clinic", GetType(String))
dt.Columns.Add("Dental Clinic", GetType(String))
dt.Columns.Add("Emp.Age", GetType(String))
dt.Columns.Add("Visit date", GetType(String))

dt.Columns(7).ColumnMapping = MappingType.Hidden
For Each gvRow As GridViewRow In Gridview1.Rows
Dim row As DataRow = dt.NewRow()
row("Serial no.") = gvRow.Cells(0).Text
row("Employee code") = DirectCast(gvRow.Cells(0).FindControl("empnum"), TextBox).Text
row("Employee Name") = DirectCast(gvRow.Cells(3).FindControl("empnme"), TextBox).Text
row("Branch(job)") = DirectCast(gvRow.Cells(8).FindControl("dropjobqs"), DropDownList).SelectedItem
row("Telephone") = DirectCast(gvRow.Cells(4).FindControl("tel"), TextBox).Text
row("General Clinic") = DirectCast(gvRow.Cells(6).FindControl("chkdelete"), CheckBox).Checked
row("Dental Clinic") = DirectCast(gvRow.Cells(7).FindControl("chkdental"), CheckBox).Checked
row("Visit date") = strtDate.Text

If (row("General Clinic").ToString = True) Then
row("General Clinic") = "*"
Else
row("General Clinic") = "-"
End If
If (row("Dental Clinic").ToString = True) Then
row("Dental Clinic") = "*"
Else
row("Dental Clinic") = "-"
End If
Try
If (row("Employee code").Length <> 0) Then
If (row("Employee code").StartsWith(0)) Then

dr = conn.MyReader("SELECT DAYEMPNBR, DEMPNAM, DBRTDAT, DPRJCDE, DEMPBRN FROM DAYBAS WHERE DAYEMPNBR = '" + DirectCast(gvRow.Cells(0).FindControl("empnum"), TextBox).Text + "' and ddayoff ='1900-01-01' ")
'cmd.Parameters.Add("@EMPNBR", SqlDbType.VarChar).Value = box1.Text
If dr.HasRows Then
While dr.Read()
strVSTDTE = DateTime.Now.ToShortDateString
row("Employee Name") = dr(0).ToString
strEMPBRTDAT = dr(1).ToString
strEMPPRJCDE = dr(2).ToString
strEMPBRN = dr(3).ToString
strBRNCDE = row("Branch(job)").ToString 'last added 9/5 2:40
strEMPBRN = dr(4).ToString

'the next step the birthday in correct dormat
strEMPAGE = Now.Year - Convert.ToDateTime(strEMPBRTDAT).Year
row("Emp.Age") = strEMPAGE

End While

Else
strEMPBRN = DirectCast(gvRow.Cells(0).FindControl("empnum"), TextBox).Text
row("Employee Name") = "please check the employee codfgdfde"

End If
dt.Columns(4).ColumnMapping = MappingType.Hidden
Else
dr = conn.MyReader("SELECT EMPNAM , EMPBRTDAT , EMPPRJCDE , EMPBRN, EMPNBR FROM EMPBAS where EMPNBR ='" + DirectCast(gvRow.Cells(0).FindControl("empnum"), TextBox).Text + "' and empmra !='12'")
If dr.HasRows Then
While dr.Read()
strVSTDTE = DateTime.Now.ToShortDateString
row("Employee Name") = dr(0).ToString
strEMPBRTDAT = dr(1).ToString
strEMPPRJCDE = dr(2).ToString
strEMPBRN = dr(3).ToString
strBRNCDE = row("Branch(job)").ToString 'last added 9/5 2:40
strEMPBRN = dr(4).ToString

'the next step the birthday in correct dormat
strEMPAGE = Now.Year - Convert.ToDateTime(strEMPBRTDAT).Year
row("Emp.Age") = strEMPAGE
End While
Else
strEMPBRN = DirectCast(gvRow.Cells(0).FindControl("empnum"), TextBox).Text
row("Employee Name") = "please check the employee dfgdfgcode"
'DirectCast(gvRow.Cells(0).FindControl("empnum"), TextBox).Focus()
End If
End If

dt.Columns(7).ColumnMapping = MappingType.Hidden

End If

Catch ex As Exception
Throw (ex)
End Try
dt.Rows.Add(row)
Next
Session("ProductsTable") = dt
Response.Redirect("preview.aspx")

End Sub
 
Share this answer
 
Comments

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