本文介绍了返回gridview边界值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 在gridview中,我设置了boundfield属性visible =false。当我从gridview中检索值时,然后 grdItemDescriptionLoad.Rows [i] .Cells [1] .Text.Trim());得到。如果我设置visible = true则grdItemDescriptionLoad.Rows [i] .Cells [1] .Text.Trim());获得价值。 但我必须隐藏这个字段。你能解释一下为什么visible =false属性会影响获取值。请帮助我。 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]。单元格[ 1 ]。Text.Trim()); cmd3.Parameters.AddWithValue( @ SevNo,grdItemDescriptionLoad.Rows [i]。单元格[ 2 ]。Text.Trim()); cmd3.Parameters.AddWithValue( @ SMcRepairDtl,grdItemDescriptionLoad.Rows [i]。单元格[ 3 ]。Text.Trim()); cmd3.ExecuteNonQuery(); } } } 这是我的gridview < asp:GridView ID = grdItemDescriptionLoad runat = server < row style cssclass = grdRow / > < ; HeaderStyle CssClass = gridheader / > < 列 > < asp:TemplateField HeaderText = 检查 > < itemtemplate > < asp:CheckBox ID = chkSelect 宽度 = 25px runat = server AutoPostBack = True oncheckedchanged = chkSelect_CheckedChanged / > < / itemtemplate > < asp:BoundField DataField = SevID HeaderText = SevID SortExpression = SevID / > < asp:BoundField DataField = SevNo HeaderText = 服务号 SortExpression = SevNo / > < asp :BoundField DataField = SevType HeaderText = 服务描述 SortExpression = SevType / > < ; / columns > 解决方案 使用css类隐藏字段而不是设置visible = false。 例如: < style type = text / css > 。隐藏 { display : none; } < / style > < asp:boundfield datafield = SevID headertext = SevID sortexpression = SevID > < item style cssclass = hidden / > < / asp:boundfield > In gridview I set a boundfield property visible="false". when I retrieve value from gridview thengrdItemDescriptionLoad.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.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: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> 解决方案 Use css class to hide the field instead of setting visible=false.For example:<style type="text/css"> .hidden { display:none; }</style><asp:boundfield datafield="SevID" headertext="SevID" sortexpression="SevID"><itemstyle cssclass="hidden" /></asp:boundfield> 这篇关于返回gridview边界值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-30 08:08