【发布时间】:2016-08-09 20:33:41
【问题描述】:
我在 gridview 中有三个下拉列表,在 gridview 中有一个文本框以及其他控件。我想从每个下拉列表中选择值并添加它们的值,并根据它在 gridview 内的文本框中显示结果。这必须为gridview的每一行完成。 我能够从每一行的下拉列表中获取选定的值,但无法在 gridview 的每一行的文本框中显示它。 所有这些都必须使用 jquery 来完成。请帮助。从过去三天开始。谢谢 任何简单的方法都将受到高度赞赏
GridView 代码:
<asp:TemplateField HeaderText ="Frequency">
<ItemTemplate>
<asp:DropDownList ID="ddlFrequency" runat="server" CssClass="col-sm-3 it1">
<asp:ListItem Value="0">Select</asp:ListItem>
<asp:ListItem Value="1">1.The lowest score for activity being done a minimal amount up to an hour a day.</asp:ListItem>
<asp:ListItem Value="2">2.The activity is done more than an hour up to a quarter of their time at work or about 2 hours a day</asp:ListItem>
<asp:ListItem Value="3">3.The activity is done for at least half of the time in a day.</asp:ListItem>
<asp:ListItem Value="4">4.The activity is done more than half of the day</asp:ListItem>
<asp:ListItem Value="5">5.The activity is done three quarters of the day</asp:ListItem>
<asp:ListItem Value="6">6.The highest score for the person performing the task all day alone</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Probability">
<ItemTemplate>
<asp:DropDownList ID="ddlProbability" runat="server" CssClass="col-sm-4 it2">
<asp:ListItem Value="0">Select</asp:ListItem>
<asp:ListItem Value="1">1.The lowest score for any low probability of injury</asp:ListItem>
<asp:ListItem Value="2">2.There is a remote chance of injury</asp:ListItem>
<asp:ListItem Value="3">3.There is an occasional chance of injury</asp:ListItem>
<asp:ListItem Value="4">4.There is a probable chance of injury</asp:ListItem>
<asp:ListItem Value="5">5.There is a likely chance of injury.</asp:ListItem>
<asp:ListItem Value="6">6.The highest score for any high probability of injury occurring.</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="Severity">
<ItemTemplate>
<asp:DropDownList ID="dllSeverity" runat="server" CssClass="col-sm-3 it3" OnSelectedIndexChanged="dllSeverity_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Value="0">Select</asp:ListItem>
<asp:ListItem Value="1">1.The lowest score for any minor injuries such as minor cuts, scrapes requiring first-aid.</asp:ListItem>
<asp:ListItem Value="2">2.Multiple first Aid, with possible health care visit with no lost time.</asp:ListItem>
<asp:ListItem Value="3">3.Potential for medical aid cases and/or resulting in few days of lost time injuries.</asp:ListItem>
<asp:ListItem Value="4">4.Long term lost time injury</asp:ListItem>
<asp:ListItem Value="5">5.The highest score for any major injuries such as fatalities/critical injuries</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Hazard Rating">
<ItemTemplate>
<asp:TextBox ID="tbHazRat" runat="server" CssClass="col-sm-1 form-control it4"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
jquery:
<script>
$(document).ready(function () {
var a, b, c;
$('.it1').change(function () {
var row = $(this);
a = $(this).find('option:selected').val();
var d = $('#<%=gvCHA.ClientID%>').find('input:text[id*="tbHazRat"]');
d.val(a);
});
$('.it2').change(function () {
var row = $(this);
b = row.find('option:selected').val();
alert(b);
});
$('.it3').change(function () {
c = $(this).find('option:selected').val();
// alert(a);
});
var e = a + b + c;
});
</script>
【问题讨论】: