我有1)文本提交 2)下拉列表 3)列表框
我为下拉列表选择值编写代码添加列表框和文本字段,我可以删除列表框值但不能删除文本字段值,请如何编写代码删除文本字段的相同添加值和列表框
<div class="col-sm-3">
<asp:TextBox ID="txtQlt" runat="server" CssClass="form-control" Width="348px" OnTextChanged="txtQlt_TextChanged" ReadOnly="true"></asp:TextBox>
</div><div class="col-md-1" style="margin-left:115px;">
<asp:Label ID="Label4" runat="server" ForeColor="Red" Text="*" ></asp:Label>
</div>
</div>
<br />
<div class="row">
<div class="col-sm-2">
<asp:Label ID="Label6" runat="server" Text="Quality reference" Font-Bold="True" Font-Names="arial, helvetica, sans-serif" Font-Size="13px"></asp:Label>
</div>
<div class="col-sm-3">
<asp:DropDownList ID ="cmbQualityRef" runat ="server" CssClass="form-control" Width="250px" >
</asp:DropDownList>
<asp:ListBox ID="lstValue" runat="server" CssClass="content" Rows="5" ValidationGroup="save"
Width="250" ></asp:ListBox>
</div>
<asp:ImageButton ID="btnAdd" runat="server" CssClass="button" Text="Add" ValidationGroup="add"
OnClick="btnAdd_Click" ImageUrl="~/img/Add.png"/>
<asp:ImageButton ID="btnImageRemove" runat="server" OnClick="btnImageRemove_Click"
ImageUrl="~/img/Remove.png" />
<div class="col-md-1" style="margin-left:16px;">
<asp:Label ID="Label7" runat="server" ForeColor="Red" Text="*" ></asp:Label>
</div>
</div>
代码背后
protected void btnImageRemove_Click(object sender, ImageClickEventArgs e)
{
try
{
if (lstValue.SelectedItem != null)
{
lstValue.Items.Remove(lstValue.SelectedItem);
}
//lstValue.Items.Remove(lstValue.SelectedItem.Text);
}
catch (Exception)
{
}
}
private void AddToList()
{
if (lstValue.Items.Count > 0)
{
txtQlt.Text = txtQlt.Text + "," + cmbQualityRef.SelectedItem.ToString();
}
else
{
txtQlt.Text = cmbQualityRef.SelectedItem.ToString();
}
ListItem itm = new ListItem();
itm.Value = cmbQualityRef.SelectedValue;
itm.Text = cmbQualityRef.SelectedItem.ToString();
lstValue.Items.Add(itm);
lstValue.Items.Remove("");
}
protected void btnAdd_Click(object sender, EventArgs e)
{
AddToList();
lstValue.Items.Remove("");
}
答案 0 :(得分:1)
根据我理解的问题,当您删除所选项目时,还要将文本框设置为空。
function SliderCtrl($) {
var self = this;
self.slider = $('#slider');
self.imgs = $('img', self.slider);
self.current = null;
self.ACTIVE_CLASS = 'is-active';
self.TIMING = 2000;
self.changeSlide = function() {
var current = $(self.current);
var next = current.next().length ? current.next() : self.imgs.first();
console.log(next, current)
current.removeClass(self.ACTIVE_CLASS);
next.addClass(self.ACTIVE_CLASS);
self.current = next;
};
window.setInterval(self.changeSlide, self.TIMING);
self.slider.removeClass('is-waiting');
}
$(document).ready(SliderCtrl);
答案 1 :(得分:0)
最后它的工作
if (lstValue.SelectedItem != null)
{
txtQlt.Text = txtQlt.Text.Replace(lstValue.SelectedItem.ToString(), "").Trim();
lstValue.Items.Remove(lstValue.SelectedItem);
}