我正在研究网格,当我点击它的一行时,网格下面板中的文本框控件必须填充选定的行值。我在客户端执行此操作并使用网格视图的onClientSelect属性。我点击该行但我无法将其分配给控件时获取值。请查看代码并告诉我
<%@ Register Assembly="obout_Grid_NET" Namespace="Obout.Grid" TagPrefix="cc1" %>
<%@ Register Assembly="obout_Interface" Namespace="Obout.Interface" TagPrefix="cc2" %>
<%@ Register TagPrefix="igg" Namespace="HR" Assembly="HR" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<script type="text/javascript">
function OnRecordFillPanel(arrSelectedRecords) {
for (var i = 0; i < arrSelectedRecords.length; i++) {
var record = arrSelectedRecords[i];
$("#ernType").text = record.EARNCDE;//**problem comes here cannot assign value to textbox.**
}
}
function addNewRec() {
$('#ernType').val('');//**and also cannot clear the value here**
}
</script>
<div >
<div>
<ISS:ISSOGrid ID="grd_EarningCodeTable" runat="server" Width="100%" OnClientSelect="OnRecordFillPanel"
AllowMultiRecordSelection="false" AutoGenerateColumns="false">
<Columns>
<cc1:Column ID="col_ErnType" DataField="EARNCDE" HeaderText="Earning Code" runat="server"
HeaderAlign="Left" Align="Left" Width="20%" />
<cc1:Column ID="col_Desc" DataField="DESCRIPTION" HeaderText="Description" runat="server"
HeaderAlign="Left" Align="Left" Width="25%" />
</ISS:ISSOGrid>
</div>
<div>
<asp:Panel ID="pnl_details" runat="server" Height="214px">
<div id="Div1" class = "showdetails" visible = "true" runat ="server" style="padding : 20px;">
<div style ="padding: 6px; width: 882px;">
<label>Earnings Type: </label>
<asp:TextBox ID = "ernType" runat ="server"></asp:TextBox>
</div>
<div style ="padding: 6px; width: 467px;">
<label>Description: </label>
<asp:TextBox ID = "desc" runat ="server" Width="300px"></asp:TextBox>
</div>
<div style ="padding: 6px;">
<asp:Button ID="btn_new" runat="server" Text="New" OnClientClick="javascript:addNewRec();" />
</asp:Panel>
</div>
</div>
</asp:Panel>
</div>
</div>
</asp:Content>
答案 0 :(得分:0)
您的问题是您使用id
的方式正在使用class
。我假设arrSelectedRecords
有多个条目,这就是你使用for循环的原因,看起来这可能是失败的原因。
for (var i = 0; i < arrSelectedRecords.length; i++) {
var record = arrSelectedRecords[i];
$(".ernType").val(record.EARNCDE);//**problem comes here cannot assign value to textbox.**
}
以上是for循环的外观。我在解释你的问题时可能错了,但我相信这可能是问题所在。因此,您必须更改id="ernType"
到class="ernType"
的所有内容。
虽然,我90%猜测你想要什么。如果您提供更多信息会很有帮助。