如何从JavaScript中的ASP.net文本框模板列读取值 - c#

我正在尝试从客户端站点JavaScript中的asp.net GridView控件读取单元格值。
下面是我的GridView HTML视图。

<asp:GridView 
ID="GridView1" 
runat="server" 
AutoGenerateColumns="False" 
Width="596px" 
DataKeyNames="Key" >

<Columns>
    <asp:BoundField DataField="Key" HeaderText="Key" SortExpression="key" Visible="False" />
    <asp:BoundField DataField="StockId" HeaderText="StockId" Visible="False" />
    <asp:BoundField DataField="Freq1" HeaderText="Freq1" Visible="False" />
    <asp:BoundField DataField="Freq2" HeaderText="Freq2" Visible="False" />     

    <asp:BoundField DataField="MedicineName" HeaderText="MedicineName" ReadOnly="true" />

    <asp:TemplateField HeaderText="DoseQty" >                                                        
        <ItemTemplate>
            <asp:TextBox ID="txtDoseQty" Text='<%# Bind("DoseQty") %>' runat="server"
            Height="23px" Width="38px" onchange="javascript:dataChange(event);" ></asp:TextBox>
        </ItemTemplate>
    </asp:TemplateField>

    <asp:BoundField DataField="DoseUOM" HeaderText="DoseUOM" ReadOnly="true" />

    <asp:TemplateField HeaderText="Duration">
        <EditItemTemplate>
            <asp:TextBox ID="Duration" runat="server" Height="16px" 
                Text='<%# Bind("Duration") %>' Width="45px" onkeypress="return isNumberKey(event);"></asp:TextBox>
        </EditItemTemplate>
        <ItemTemplate>
            <asp:Label ID="lblDuration" Text='<%# Bind("Duration") %>'  runat="server"></asp:Label>
        </ItemTemplate>
    </asp:TemplateField>

    <asp:TemplateField HeaderText="Delete All">
        <HeaderTemplate>
            <asp:CheckBox ID="chkHeaderDelete" runat="server" Text="Delete All" 
                onclick="javascript:SelectheaderCheckboxes(this)" />                                                            
        </HeaderTemplate>
        <ItemTemplate>
            <asp:CheckBox ID="chkItemDelete" runat="server" AutoPostBack="true"
                Text="Delete" onclick="javascript:SelectitemCheckboxes(this)"  />
        </ItemTemplate>
    </asp:TemplateField>

    <asp:CommandField HeaderText="Update" 
        ShowEditButton="True"                                                         
        CausesValidation="false"  />

</Columns>

我正在使用javascript函数读取此网格视图。

var grid = document.getElementById("<%= GridView1.ClientID %>");
var OutputString = "";
if (grid.rows.length > 0) {
for (i = 1; i < grid.rows.length - 1; i++) {
    for (j = 0; j < grid.rows[i].cells.length; j++) {
        OutputString += "grid.rows[i].cells[" + j + "]  :" + grid.rows[i].cells[j] +
            "\ngrid.rows[i].cells[" + j + "].innerText :" + grid.rows[i].cells[j].innerText;
        OutputString += "\n\n";             
    }
}
}

这是我的输出。

---------------------------
Message from webpage
---------------------------
grid.rows[i].cells[0]  :[object]
grid.rows[i].cells[0].innerText :Abd pant XXXL

grid.rows[i].cells[1]  :[object]
grid.rows[i].cells[1].innerText : 

grid.rows[i].cells[2]  :[object]
grid.rows[i].cells[2].innerText :Pieces

grid.rows[i].cells[3]  :[object]
grid.rows[i].cells[3].innerText :1 

grid.rows[i].cells[4]  :[object]
grid.rows[i].cells[4].innerText :Delete 

grid.rows[i].cells[5]  :[object]
grid.rows[i].cells[5].innerText :Edit

---------------------------
OK   
---------------------------

我的问题是我不知道如何从grid.rows [i] .cells [1]中获取值,该网格包含ASP.net TextBox控件作为TemplateColumn。

每个建议将不胜感激。

参考方案

 function getgridvalue()
     {
      // Call this on button click
     Array obj;
      var gridview=document.getElementById("<GridView ID here>"); //Grab a reference to the Grid
      for (i=1;i<gridview.rows.length;i++) //Iterate through the rows
       {
        obj[i]=gridview.rows[i].cells[1].firstChild.value; //get the values
       }

     }

这是一个大概的方法,希望能有所帮助。

将Web用户控件添加到页面时,asp按钮onclick不会触发 - javascript

我正在使用使用Visual Studio模板创建的Web表单应用程序。模板具有一个内容占位符,该占位符被访问的任何页面的内容替换。有问题的页面有几个服务器控件,例如文本框,标签和按钮。当我单击我的更新按钮时,它可以正常工作,这些值会回传并更新数据库。我想在所有子页面上创建通用的登录提示。我的导航栏(位于我的母版页中)具有引导程序设置。我在导航栏中添加了一个下…

Asp.net发送信息表单到页面 - c#

我正在尝试使用弹出窗口中的新信息更新旧页面。到目前为止,我尝试过将结果保存在会话中Session["Data"] = DLvrijecampingplaatsen.SelectedItem; 然后当它达到Page_Load时,将其重新加载回旧页面if (Session["Data"] != null) { LBkies…

与Mootools Scriptmanager Ajax Asp.net发生冲突? - c#

我正在尝试不同的方法来使这项工作成功,但是没有成功。我正在尝试将mootools与asp.net应用程序集成。我只想用它为我的网站添加一些效果。我也使用更新面板,scriptmanager,因为不希望有完整的回发。在控制台上引发错误TypeError:clientID.startsWith不是函数,并且在进行更新时brwoser reset...。这是整个代…

Div单击与单选按钮相同吗? - php

有没有一种方法可以使div上的click事件与表单环境中的单选按钮相同?我只希望下面的div提交值,单选按钮很丑代码输出如下:<input id="radio-2011-06-08" value="2011-06-08" type="radio" name="radio_date&#…

故障排除“警告:session_start():无法发送会话高速缓存限制器-标头已发送” - php

我收到警告:session_start()[function.session-start]:无法发送会话缓存限制器-标头已发送(错误输出开始如果我将表单数据提交到其他文件进行处理,则可以正常工作。但是,如果我将表单数据提交到同一页面,则会出现此错误。请建议<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0…