Rajaa Khalifeh

Rajaa Khalifeh

  • NA
  • 53
  • 6.5k

Pass grid-view Values even if column is not visible

Apr 21 2020 11:06 AM
hello i am trying to pass values from gridview to another form but my problem is that when i make the coloumn visible=false, data of this column is to showing up so any help how can i get value of coloumn even if the coloumn is unvisible..
 
my grid view data : 
 
  1. <ItemTemplate>  
  2. <asp:Button ID="Button1" Text="Edit" runat="server" BorderStyle="None" OnClick="Send" ForeColor="CornflowerBlue" CssClass="button1" OnClientClick = "SetTarget();" Width="50px"/>  
  3. </ItemTemplate>  
  4. </asp:TemplateField>  
and on page load of this page :
 
  1. protected void Page_Load(object sender, EventArgs e)  
  2.   {  
  3.       Label1.Visible = false;  
  4.        
  5.   
  6.        if (!IsPostBack)  
  7.           BindGrid();  
  8.   
  9.        GridView1.Columns[0].Visible = false;  
  10.        GridView1.Columns[1].Visible = false;  
  11.   }  
and the send edit button here i tried to show the coloumn and send the data with the button but it didnt work:
  1. protected void Send(object sender, EventArgs e)  
  2.    {  
  3.   
  4.        //Reference the Button.  
  5.        Button btnSend = sender as Button;  
  6.   
  7.        //Reference the GridView Row.  
  8.   
  9.        GridViewRow row = btnSend.NamingContainer as GridViewRow;  
  10.   
  11.   
  12.        //Save the GridView Row in Session.  
  13.        GridView1.Columns[1].Visible = true;  
  14.        Session["Row"] = row;  
  15.   
  16.        //Redirect to other Page.  
  17.        Response.Redirect("EditAddPack.aspx");  
  18.    }  
finally my another page load iam getting the data like this with all the columns that are only visible = true;
  1. if (Session["Row"] != null)  
  2.                    {  
  3.                        //Fetch the GridView Row from Session.  
  4.                        GridViewRow row = Session["Row"as GridViewRow;  
  5.   
  6.                        //Fetch and display the Cell values.  
  7.   
  8.                        editstdidlbl.Text = row.Cells[1].Text; // here iam not getting this lable since i put it unvisible in the gridview  
  9.                        editCoachdroplist.SelectedValue = row.Cells[2].Text;  
  10.                        editSTDDropDownList.SelectedItem.Text = row.Cells[3].Text;  
  11.   
  12.                        editSessiontxt.Text = row.Cells[4].Text;  
  13.                        editpackDropDownList.SelectedValue = row.Cells[5].Text;  
  14.                        editamounttxt.Text = row.Cells[6].Text;  
  15.                        editstarttxt.Text = row.Cells[7].Text;  
  16.                        editStatusDropDownList.SelectedValue = row.Cells[8].Text;  
  17.                        editremarkid.Value = row.Cells[9].Text;  
  18.   
  19.   
  20.   
  21.                    }  
Please Help!! 
 

Answers (2)