gridview有一列其中单元格式空的   列代码:<asp:BoundField HeaderText="列名称" DataField="fieldName" HeaderStyle-Width="15%" />   js赋值的时候是document.getElementById("gvwExcelField").rows(3).cells(1).innerHTML="C_Name"   然后在Gridview中这个值也显示出来了   但是在后台取的时候  string xx = gvwExcelField.Rows[3].Cells[1].Text;  xx总是等于"&nbsp;"  求解!

解决方案 »

  1.   

     gvwExcelField.Rows[3].Cells[1].Value//改成Value看看
      

  2.   

    gvwExcelField.Rows[3].Cells[1].Controls[0]
      

  3.   

    document.getElementById("gvwExcelField").rows(3).cells(1).innerHTML="C_Name"
    你显示出来的有没有值呢?
      

  4.   

    js中赋值,在后台直接用gvwExcelField.Rows[3].Cells[1].Text是获取不到的,要给你js设置的那个元素设置name属性,然后用Request.Form["name属性名称"]来获取
      

  5.   

    能不能给个例子 
     <asp:GridView ID="gvwExcelField" runat="server" Width="100%" AutoGenerateColumns="False"
                                            OnRowCommand="gvwExcelField_RowCommand">
                                            <Columns>
                                                <asp:BoundField HeaderText="序号" DataField="columnSortID" HeaderStyle-Width="6%" HeaderStyle-Height="35" />
                                                <%--<asp:BoundField HeaderText="列名称" DataField="fieldName" HeaderStyle-Width="15%" />--%>
                                                <asp:TemplateField HeaderText="列名称" HeaderStyle-Width="15%">
                                                    <ItemTemplate>
                                                        <asp:Label ID="lblFiledName" runat="server" Text='<%# Eval("FieldName") %>' name="lblFiledName"></asp:Label>                                                    <asp:HiddenField ID="hidFiled" runat="server" />
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="对应操作" HeaderStyle-Width="15%">
                                                    <ItemTemplate>
                                                        <asp:ImageButton ID="IbtRowUp" runat="server" ImageUrl="~/Import/Images/uparrow.gif"
                                                            Style="cursor: pointer" CommandName="row_up" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"columnSortID")%>' />
                                                        <asp:ImageButton ID="IbtRowDown" runat="server" ImageUrl="~/Import/Images/downarrow.gif"
                                                            Style="cursor: pointer" CommandName="row_down" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"columnSortID")%>' />
                                                      <%--  <asp:ImageButton ID="IbtModifyRow" runat="server" ImageUrl="~/Import/Images/field.gif"
                                                            Style="cursor: pointer" OnClick="ModifyExcelFiled('<%#Eval("columnSortID") %>')" />--%>
                                                        <img src="Images/field.gif" style="cursor: pointer" alt="修改字段" onclick="ModifyExcelFiled('<%#Eval("columnSortID") %>')" />
                                                        <img src="Images/del_None.gif" style="cursor: pointer" alt="清除字段" onclick="DeleteExcelFiled('<%#Eval("columnSortID") %>')" />
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                                                        </Columns>
                                        </asp:GridView>
    后台的话怎么获取呢 怎么获取  列名称 这一列的 每个单元格的值呢
      

  6.   

    前台代码
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="jQuery-14.aspx.cs" Inherits="jQuery_14" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>无标题页</title>
        <style type="text/css">
            #panel{position:relative;width:100px;height:100px;border:1px solid #0050D0;background:#96E555;cursor:pointer;}
        </style>
        <script type="text/javascript" src="jquery-1.6.1.min.js"></script>
        <script type="text/javascript">
            $(function(){
    //             $("#panel").toggle(function(){
    //                $(this).animate({left: "+=500px",height:"+=200px"},3000);
    //            },function(){
    //                $(this).animate({left: "-=500px",height:"-=200px"},3000);
    //            })
                $("#panel").css("opacity","0.5");
                $("#panel").click(function(){
                    $(this).animate({left:"400px",height:"200px",opacity:"1"},3000)
                            .animate({top:"200px",width:"200px"},3000)
                            .fadeOut("slow");
                })
            })
           function addOption()
           {
              var slt=document.getElementById("sl");
              slt.options.add(new Option("1","测试"));
           }
        </script>
    </head>
    <body onload="addOption()">
        <form id="form1" runat="server">
        <div>
            <div id="panel"></div>
            <select name="slT" id="sl">
                
            </select>
            <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
        </div>
        </form>
    </body>
    </html>
    后台代码获取
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;public partial class jQuery_14 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }
        protected void Button1_Click(object sender, EventArgs e)
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('" + Request.Form["slT"] + "')", true);
        }
    }
    这里就是获取select控件js赋值的
      

  7.   

    现在是一个模板列啊  这一列的每个单元格都有相同的name  要怎么取到每个单元格的值呢
      

  8.   

      <asp:TemplateField HeaderText="列名称" HeaderStyle-Width="15%">
                                                    <ItemTemplate>
                                                        <asp:Label ID="lblFiledName" runat="server" Text='<%# Eval("FieldName") %>' [color=#FF0000]name="lblFiledName"></asp:Label>[/color]                                                    <asp:HiddenField ID="hidFiled" runat="server" />
                                                    </ItemTemplate>
                                                </asp:TemplateField>
    怎么取不一样啊
      

  9.   

    在gvwExcelField_RowCommand 事件中获取值
    int index = int.Parse(e.CommandArgument.ToString());
    Label lblcontactNos = this.gvwExcelField.Rows[index].FindControl("lblFiledName") as Label;            string lblcontactNos = lblcontactNos.Text.ToString();
      

  10.   

    <asp:TemplateField HeaderText="列名称" HeaderStyle-Width="15%">
      <ItemTemplate>
      <asp:Label ID="lblFiledName" runat="server" Text='<%# Eval("FieldName") %>' name='<% Eval("columnSortID")%>'></asp:Label> <asp:HiddenField ID="hidFiled" runat="server" />
      </ItemTemplate>
      </asp:TemplateField>用columnSortID命名不行吗
      

  11.   

    Label lblcontactNos = this.gvwExcelField.Rows[index].FindControl("lblFiledName") as Label;string lblcontactNos = lblcontactNos.Text.ToString(); 这个不可以吗
      

  12.   

    Gridview的样式  在模板列里放Label和HiddenFiled<asp:GridView ID="gvwExcelField" runat="server" Width="100%" AutoGenerateColumns="False"
                                            OnRowCommand="gvwExcelField_RowCommand">
                                            <Columns>
                                                <asp:BoundField HeaderText="序号" DataField="columnSortID" HeaderStyle-Width="6%" HeaderStyle-Height="35" />
                                                <asp:TemplateField HeaderText="列名称" HeaderStyle-Width="15%">
                                                    <ItemTemplate>
                                                        <asp:Label ID="lblFiledName" runat="server" Text='<%# Eval("FieldName") %>' name="lblFiledName"></asp:Label>
                                                        <asp:HiddenField ID="HidFiledName" runat="server" />
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="对应操作" HeaderStyle-Width="15%">
                                                    <ItemTemplate>
                                                        <asp:ImageButton ID="IbtRowUp" runat="server" ImageUrl="~/Import/Images/uparrow.gif"
                                                            Style="cursor: pointer" CommandName="row_up" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"columnSortID")%>' />
                                                        <asp:ImageButton ID="IbtRowDown" runat="server" ImageUrl="~/Import/Images/downarrow.gif"
                                                            Style="cursor: pointer" CommandName="row_down" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"columnSortID")%>' />
                                                        <img src="Images/field.gif" style="cursor: pointer" alt="修改字段" onclick="ModifyExcelFiled('<%#Eval("columnSortID") %>')" />
                                                        <img src="Images/del_None.gif" style="cursor: pointer" alt="清除字段" onclick="DeleteExcelFiled('<%#Eval("columnSortID") %>')" />
                                                    </ItemTemplate>
                                                </asp:TemplateField>
                                            </Columns>
                                        </asp:GridView>下面是给单元格赋值  在模板列里放置一个Label和一个HiddenFiled  给空单元格赋值的时候同时值赋给这两个空件 if (win) {
                    var obj = document.getElementById("gvwExcelField");
                    obj.rows(rowCount - 1 + 1).cells[1].childNodes[0].innerText = win;
                    obj.rows(rowCount - 1 + 1).cells[1].childNodes[1].value = win;
                }
    取值的时候  先取Label的值  如果Label的值为空(label取到的值一定为空)  就取HiddenFiled的值 string ExcelFiled = ((Label)gvwExcelField.Rows[b].FindControl("lblFiledName")).Text;
                            if (ExcelFiled == "")
                            {
                                ExcelFiled = ((HiddenField)gvwExcelField.Rows[b].FindControl("HidFiledName")).Value;
                            }
                            if (ExcelFiled != "")
                            {
                               //此处代码省略
                            }
      

  13.   

    大哥,我照着你的做但是label弹出来的还是label,而hiddenfield弹出来是空,到底是什么原因