public DataTable FetchCustomerType()
{
string sql = "select distinct Customer_TypeID,Customer_Type from tbl_CustomerType";
SqlDataAdapter da = new SqlDataAdapter(sql, constr);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public DataTable FetchFileFrequency()
{
string sql = "SELECT distinct FileFrequency_ID,FileFrequency FROM [tbl_FileFrequency]";
SqlDataAdapter da = new SqlDataAdapter(sql, constr);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
protected void RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
DropDownList ddlgvFileFreq = (DropDownList)e.Row.FindControl("ddlgvFileFreq"); //getting binded
ddlgvFileFreq.DataSource = FetchFileFrequency();
ddlgvFileFreq.DataTextField = "FileFrequency";
ddlgvFileFreq.DataValueField = "FileFrequency_ID";
ddlgvFileFreq.DataBind();
ddlgvFileFreq.Items.FindByValue((e.Row.FindControl("lblFileFreq") as Label).Text).Selected = true;
DropDownList ddlgvCustomerType = (DropDownList)e.Row.FindControl("ddlgvCustomerType");
ddlgvCustomerType.DataSource = FetchCustomerType();
ddlgvCustomerType.DataTextField = "Customer_Type";
ddlgvCustomerType.DataValueField = "Customer_TypeID";
ddlgvCustomerType.DataBind();
ddlgvCustomerType.Items.FindByValue((e.Row.FindControl("lblCustType") as Label).Text).Selected = true;
}
}
}
catch (Exception ex)
{
//log error
errorlog.WriteErrorLog(ex.ToString());
}
}
我只想选择&#39;品牌&#39;但是当我使用<span class="filter-dot hidden"></span>
Brand <span class="filter-count hidden">(0)</span>
<input type="hidden" class="js-filter-count" value="0">
<span class="filter-clear hidden" data-displaytype="checkBox">
Clear
</span>
时,它会选择&#39;品牌&#39;以及&#39;清除&#39;任何人都可以建议我如何选择&#39;品牌&#39;仅?
答案 0 :(得分:0)
将“Brand”包装到一个更具体的选择器中并仅选择它:
<div class="filter-type-name">
<span class="filter-dot hidden"></span>
<span class="filter-name">Brand</span>
<span class="filter-count hidden">(0)</span>
<input type="hidden" class="js-filter-count" value="0">
<span class="filter-clear hidden" data-displaytype="checkBox">Clear</span>
</div>
然后:
$('div.filter-type-name .filter-name').text()
否则,使用childNodes集合来迭代它并选择您需要的内容(Node.TEXT_NODE === 3
),但这不太实用:
$('div.filter-type-name')[0].childNodes
答案 1 :(得分:0)
使用类或ID给Brand
自己的周围元素,比如说“品牌名称”并执行:
$('div.filter-type-name .brand-name').text()
或保持原样并执行:
$('div.filter-type-name').text().split(' ')[0];
答案 2 :(得分:0)
THIS ONE似乎解决了这个问题。
这里是JSFiddle: https://jsfiddle.net/flamedenise/9dsfbkms/
var text = ($(".filter-type-name").clone().children().remove().end().text()).trim();
alert(text);
答案 3 :(得分:0)
没有包装您的品牌&#39;字符串到标签。您可以使用以下方法。
假设这是您的代码:
<div class="filter-type-name">
<span class="filter-dot hidden"></span>
Brand
<span class="filter-count hidden">(0)</span>
<input type="hidden" class="js-filter-count" value="0">
<span class="filter-clear hidden" data-displaytype="checkBox"> Clear </span>
</div>
您可以使用正则表达式匹配脚本来检查所需的文本。
var str = $('div.filter-type-name').text();
var res = str.match(/Brand/g);
要查看输出,
<p id="demo"> </p>
document.getElementById("demo").innerHTML = res;