gpt4 book ai didi

c# - Javascript 读取 ASP GridVIEW BoundField Column which is visible false

转载 作者:太空宇宙 更新时间:2023-11-03 14:08:06 24 4
gpt4 key购买 nike

<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(不是 JQUERY)从客户端的 Asp.net GridView 中读取一个值。
但是在我尝试了几次之后,我发现我不知道如何在纯 javascript 中从 BoundField 列中读取一个值为 "Visile=False"的值。

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++)
{
if (j == 1)
{
OutputString += "grid.rows[i].cells[" + j + "] :" + grid.rows[i].cells[j] +
"\ngrid.rows[i].cells[" + j + "].innerText :" + grid.rows[i].cells[j].firstChild.value;
OutputString += "\n\n";
}
else
{
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";
}
}
}
}

输出

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 : 12

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

在 Javascript 中,是否可以从 bondfield 中读取可见的 false 值?

[更新]
我仅从文本框模板字段和 BoundField 不是“Visible=False” 获得的所有输出。

请告诉我方法,我们将不胜感激。

最佳答案

Visible="false"的控件不会被渲染,因此不会生成 HTML。

如果你想让你的控件不可见但仍然引用它们,首先删除 Visible="false"然后你可以在你的控件上使用 CSS:

style="display:none;" 

或者您可以在呈现 RowDataBound 事件后隐藏 GridView 列(您的前四个 BoundFields):

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[column_index].Visible = false;
}

关于c# - Javascript 读取 ASP GridVIEW BoundField Column which is visible false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8756192/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com