Click here to Skip to main content
15,885,117 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In gridview I set a boundfield property visible="false". when I retrieve value from gridview then
grdItemDescriptionLoad.Rows[i].Cells[1].Text.Trim()); gets "". If I set visible=true then grdItemDescriptionLoad.Rows[i].Cells[1].Text.Trim()); gets value.
But I have to hide this field. Can you explain me why visible="false" property affects to get the value. Please help me.
C#
if (grdItemDescriptionLoad.Rows.Count > 0)
           {
               for (int i = 0; i < grdItemDescriptionLoad.Rows.Count; i++)
               {
                   CheckBox chkb = (CheckBox)grdItemDescriptionLoad.Rows[i].FindControl("chkSelect");
                   if (chkb.Checked == true)
                   {
                       SqlCommand cmd3 = new SqlCommand("Smt_Mc_Repair_Details_Record_Save", cn);
                       if (cn.State == ConnectionState.Closed)
                       {
                           cn.Open();
                       }
                       cmd3.CommandType = CommandType.StoredProcedure;
                       cmd3.Parameters.AddWithValue("@SMcID", hdAction.Value);
                       cmd3.Parameters.AddWithValue("@SAssetNo", ddlAssetNo.SelectedValue);
                       cmd3.Parameters.AddWithValue("@SSevID", grdItemDescriptionLoad.Rows[i].Cells[1].Text.Trim());
                       cmd3.Parameters.AddWithValue("@SevNo", grdItemDescriptionLoad.Rows[i].Cells[2].Text.Trim());
                       cmd3.Parameters.AddWithValue("@SMcRepairDtl", grdItemDescriptionLoad.Rows[i].Cells[3].Text.Trim());

                       cmd3.ExecuteNonQuery();

                   }
               }
           }

Here is my gridview
ASP.NET
<asp:GridView ID="grdItemDescriptionLoad"  runat="server"
      <rowstyle cssclass="grdRow" />
     <HeaderStyle CssClass="gridheader" />
    <columns>
    <asp:TemplateField HeaderText="Check">
    <itemtemplate>
        <asp:CheckBox ID="chkSelect" Width="25px" runat="server" AutoPostBack="True"
            oncheckedchanged="chkSelect_CheckedChanged" />
    </itemtemplate>

     <asp:BoundField DataField="SevID" HeaderText="SevID" SortExpression="SevID" />
     <asp:BoundField DataField="SevNo" HeaderText="Service No" SortExpression="SevNo" />
     <asp:BoundField DataField="SevType" HeaderText="Service Description" SortExpression="SevType" />
    </columns>
Posted
Updated 17-Dec-14 23:30pm
v4

1 solution

Use css class to hide the field instead of setting visible=false.

For example:

ASP.NET
<style type="text/css">
     .hidden
     {
         display:none;
     }
</style>

<asp:boundfield datafield="SevID" headertext="SevID" sortexpression="SevID">
<itemstyle cssclass="hidden" />
</asp:boundfield>
 
Share this answer
 
v2
Comments
Sumon562 18-Dec-14 6:11am    
Thanks it works nice

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