locked
Showing fields in the Details Form that are set invisible RRS feed

  • Question

  • User-643157890 posted

    I have a List.aspx with a Gridview with ten fields (columns). I wanted to show only six out of ten fields. The other 4 fields are set invisible using the smart tag to configure the data source. I enable Selection on the Gridview. When selecting, it will redirect to the ListDetails.aspx to show a specific item in detail.

    //List.aspx
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { GridViewRow row = GridView1.SelectedRow; Session["Id"] = row.Cells[1].Text; Session["Name"] = row.Cells[2].Text; Session["Section"] = row.Cells[3].Text; Session["Summary"] = row.Cells[4].Text; Session["Domain"] = row.Cells[5].Text; Session["Date"] = row.Cells[6].Text; Session["Type"] = row.Cells[7].Text; //does not show in the LD.aspx Session["Justification"] = row.Cells[8].Text; //does not show in the LD.aspx Session["OfficePhone"] = row.Cells[9].Text; //does not show in the LD.aspx Session["Email"] = row.Cells[10].Text; //does not show in the LD.aspx Response.Redirect("ListDetails.aspx"); }
    //ListDetails.aspx
    protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
    
                    if (Session["Role"] != null)
                    {  
                        txtId.Text = Session["Id"].ToString();
                        txtName.Text = Session["Name"].ToString();
                        txtSection.Text = Session["Section"].ToString();
                        txtSummary.Text = Session["Summary"].ToString();
                        ddlDomain.Text = Session["Domain"].ToString();
                        txtDate.Text = Session["Date"].ToString();
                        ddlType.Text = Session["Type"].ToString();
                        txtJustification.Text = Session["Justification"].ToString();
                        txtPhoneNumber.Text = Session["OfficePhone"].ToString();
                        txtEmailAddress.Text = Session["Email"].ToString();
                         
                    }
                }
            }
    

    I want to show ALL of fields including those fields that are set invisible in the List.aspx.  However, when I click on SELECT to select a row on the list, those fields that are set invisible won't show up in the ListDetails.aspx. Can you please help me to find out why and how to fix it?  Thank you in advance

       

    Tuesday, August 2, 2016 8:35 PM

Answers

  • User-1716253493 posted

    I sugest you to pass id only then get detailed data based the id from db in details page

                    if (Session["Role"] != null)
                    {  
                        string id = Session["Id"].ToString();
                        //next data from db
                         
                    }



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 3, 2016 7:20 AM
  • User-271186128 posted

    Hi newUser15,

    From your description, I suggest you could set a break point in the SelectedIndexChanged event and check whether you could get the invisible columns’ value. I suppose perhaps you are using the Visible property to make this columns invisible, which is the reason of your error. I suggest you could try to hide the columns using the CSS display attribute. Here is some code. You could refer to it.

    List.aspx:

    <style type="text/css">
            .countryclass{
                display:none;
            }
    </style>
    <asp:GridView ID="GridView1" runat="server" HeaderStyle-BackColor ="#3AC0F2" HeaderStyle-ForeColor="White" 
                    RowStyle-BackColor="#A1DCF2" AlternatingRowStyle-BackColor="White" AlternatingRowStyle-ForeColor="#000"
                     AutoGenerateColumns ="False" AllowPaging ="True" OnPageIndexChanging ="onpageindexchanging" AutoGenerateSelectButton="true" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" >
    <AlternatingRowStyle BackColor="White" ForeColor="#000000"></AlternatingRowStyle>
                    <Columns >
                     <asp:BoundField DataField ="Contactname" HeaderText="Contactname "  ItemStyle-Width="150px">
    <ItemStyle Width="150px"></ItemStyle>
                        </asp:BoundField>
                      <asp:BoundField DataField ="City" HeaderText ="City" ItemStyle-Width="100px">                   
    <ItemStyle Width="100px"></ItemStyle>
                        </asp:BoundField>
                       <asp:BoundField DataField ="Country" HeaderText ="Country" ItemStyle-Width="100px"
                            ItemStyle-CssClass="countryclass" HeaderStyle-CssClass="countryclass" FooterStyle-CssClass="countryclass" >                   
    <ItemStyle Width="100px"></ItemStyle>
                        </asp:BoundField>
                    </Columns>            
    
    <HeaderStyle BackColor="#3AC0F2" ForeColor="White"></HeaderStyle>
    
    <RowStyle BackColor="#A1DCF2"></RowStyle>
                </asp:GridView>
    

    Code Behind:

      protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
            {
                string id = GridView1.SelectedRow.Cells[0].Text;         
                Session["contactName"] = GridView1.SelectedRow.Cells[1].Text;
                Session["city"] = GridView1.SelectedRow.Cells[2].Text;                   
                Session["country"] = GridView1.SelectedRow.Cells[3].Text; 
                Response.Redirect("ListDetails.aspx ");
            }
    

    ListDetails.aspx:

    protected void Page_Load(object sender, EventArgs e)
            {
                DataTable dt = new DataTable();
                dt.Columns.AddRange(new DataColumn[3] { new DataColumn("contactname",typeof(string)),
                           new DataColumn("City",typeof(string)),
                         new DataColumn("Country",typeof(string)), });          
                string name = (string)Session["contactName"];
                string city = (string)Session["city"];
                string country = (string)Session["Country"];
                dt.Rows.Add(name, city, country);
                ListView1.DataSource = dt;
                ListView1.DataBind();
            }
    

    Hope this can help you. If you have any question and confusion about the problem. Please don't hesitate to let me know.

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 4, 2016 3:02 AM

All replies

  • User-1716253493 posted

    I sugest you to pass id only then get detailed data based the id from db in details page

                    if (Session["Role"] != null)
                    {  
                        string id = Session["Id"].ToString();
                        //next data from db
                         
                    }



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 3, 2016 7:20 AM
  • User-271186128 posted

    Hi newUser15,

    From your description, I suggest you could set a break point in the SelectedIndexChanged event and check whether you could get the invisible columns’ value. I suppose perhaps you are using the Visible property to make this columns invisible, which is the reason of your error. I suggest you could try to hide the columns using the CSS display attribute. Here is some code. You could refer to it.

    List.aspx:

    <style type="text/css">
            .countryclass{
                display:none;
            }
    </style>
    <asp:GridView ID="GridView1" runat="server" HeaderStyle-BackColor ="#3AC0F2" HeaderStyle-ForeColor="White" 
                    RowStyle-BackColor="#A1DCF2" AlternatingRowStyle-BackColor="White" AlternatingRowStyle-ForeColor="#000"
                     AutoGenerateColumns ="False" AllowPaging ="True" OnPageIndexChanging ="onpageindexchanging" AutoGenerateSelectButton="true" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" >
    <AlternatingRowStyle BackColor="White" ForeColor="#000000"></AlternatingRowStyle>
                    <Columns >
                     <asp:BoundField DataField ="Contactname" HeaderText="Contactname "  ItemStyle-Width="150px">
    <ItemStyle Width="150px"></ItemStyle>
                        </asp:BoundField>
                      <asp:BoundField DataField ="City" HeaderText ="City" ItemStyle-Width="100px">                   
    <ItemStyle Width="100px"></ItemStyle>
                        </asp:BoundField>
                       <asp:BoundField DataField ="Country" HeaderText ="Country" ItemStyle-Width="100px"
                            ItemStyle-CssClass="countryclass" HeaderStyle-CssClass="countryclass" FooterStyle-CssClass="countryclass" >                   
    <ItemStyle Width="100px"></ItemStyle>
                        </asp:BoundField>
                    </Columns>            
    
    <HeaderStyle BackColor="#3AC0F2" ForeColor="White"></HeaderStyle>
    
    <RowStyle BackColor="#A1DCF2"></RowStyle>
                </asp:GridView>
    

    Code Behind:

      protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
            {
                string id = GridView1.SelectedRow.Cells[0].Text;         
                Session["contactName"] = GridView1.SelectedRow.Cells[1].Text;
                Session["city"] = GridView1.SelectedRow.Cells[2].Text;                   
                Session["country"] = GridView1.SelectedRow.Cells[3].Text; 
                Response.Redirect("ListDetails.aspx ");
            }
    

    ListDetails.aspx:

    protected void Page_Load(object sender, EventArgs e)
            {
                DataTable dt = new DataTable();
                dt.Columns.AddRange(new DataColumn[3] { new DataColumn("contactname",typeof(string)),
                           new DataColumn("City",typeof(string)),
                         new DataColumn("Country",typeof(string)), });          
                string name = (string)Session["contactName"];
                string city = (string)Session["city"];
                string country = (string)Session["Country"];
                dt.Rows.Add(name, city, country);
                ListView1.DataSource = dt;
                ListView1.DataBind();
            }
    

    Hope this can help you. If you have any question and confusion about the problem. Please don't hesitate to let me know.

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 4, 2016 3:02 AM
  • User-643157890 posted

    That makes sense to me. Thanks.

    Friday, August 5, 2016 1:42 AM
  • User-643157890 posted

    Thank you, Dillion. It's interesting solution. And it makes sense to me so I will mark it as answer

    Friday, August 5, 2016 3:28 AM
  • User-643157890 posted

    Your solution is simple, oned_gk. Thanks.

    Friday, August 5, 2016 3:30 AM