有没有快速的方法转换List<string>
为string
C#中的逗号分隔?
我这样做但也许有更快或更有效的方式?
List<string> ls = new List<string>();
ls.Add("one");
ls.Add("two");
string type = string.Join(",", ls.ToArray());
Run Code Online (Sandbox Code Playgroud)
PS:在这个网站上搜索过但大多数解决方案都是针对Java或Python的
在我的表单中,我需要插入"text"类型的不同输入.输入必须是带有名称和ID的html控件.因为我将此表单发送到外部URL.
为了验证,我在所有输入中运行runat = server,然后我可以使用requiredfieldvalidator.
但问题是,当我在浏览页面后查看源名称和ID都已更改.例如
<input id="first_name" class="formright" type="text" name="first_name" runat="server" />
Run Code Online (Sandbox Code Playgroud)
改变为
<input name="ctl00$cphContent$first_name" type="text" id="ctl00_cphContent_first_name" class="formright">
Run Code Online (Sandbox Code Playgroud)
我必须使用html控件,因为外部postbackurl查看name和id值以查找控件.所以我不能使用asp控件.因为我使用了runat = server的html控件
我感谢任何帮助
谁知道将List
字符串转换为最简单的方法ArrayList
?
我尝试(ArrayList)
在代码之前设置,但这没有做任何事情.
我做递归以在List中找到一个具有多个子节点的长值,这些子节点也可以有子节点.
以下方法:
public TaxonomyData getTaxonomyData(long taxId, List<TaxonomyData> TaxonomyTree, TaxonomyData output)
{
//find taxid in the taxonomy tree list and return the taxonomydata
foreach (TaxonomyData td in TaxonomyTree)
{
if (td.TaxonomyId == taxId)
{
output = td;
//return td; => when doing a return here means I already found a match so it is not necessary to do all the recursion.
}
else if (td.Taxonomy.Length > 0)
{
getTaxonomyData(taxId, td.Taxonomy.ToList(), output);
}
}
return output;
}
Run Code Online (Sandbox Code Playgroud)
有可能当我这样做return td;
(见注释行)我的整个递归停止了吗?
谢谢
我将List绑定到DropDownList.但我想为每个列表项的值提供其他值.
我有以下ddl和列表:
List<string>
Run Code Online (Sandbox Code Playgroud)
运动,排球,橄榄球
<select>
<option selected="selected" value="0"> Alle soorten</option>
<option value="sport">sport</option>
<option value="volleyball">volleyball</option>
<option value="rugby">rugby</option>
</select>
Run Code Online (Sandbox Code Playgroud)
但我想跟随(值中的ID)
<select>
<option selected="selected" value="0"> Alle soorten</option>
<option value="1">sport</option>
<option value="2">volleyball</option>
<option value="3">rugby</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我如何创建一个List,以便获得上面的下拉列表.
谢谢
我想以编程方式获得以下HTML:
<ul><li><a href="#"></a></li></ul>
Run Code Online (Sandbox Code Playgroud)
我可以补充<li>
到<ul>
.不过<a>
到<li>
是不可能的.
我的代码:
BulletedList ul = new BulletedList();
ListItem li = new ListItem();
HyperLink hl = new HyperLink();
ul.Items.Add(li);
// li has no property Controls or Items
Run Code Online (Sandbox Code Playgroud) 在我的网站中,我在母版页中有一个搜索功能(没有设置默认按钮,也没有在窗体中).在一个内容页面,我有一个登录,我使用带有defaultbutton的asp面板.但是当我点击登录文本框中的Enter然后我的网站继续前往搜索事件处理程序......可能是什么原因?
一些代码:
//on content page
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(Button1.Text);
}
<asp:Panel ID="pnl1" runat="server" DefaultButton="Button1">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:LinkButton ID="Button1" runat="server" Text="Button1" OnClick="Button1_Click" />
</asp:Panel>
//on master page:
protected void btnSearch_Click(object sender, EventArgs e)
{
if (!txtSearch.Text.Equals(""))
{
Response.Redirect("searchresults.aspx?search=" + txtSearch.Text);
}
}
<div id="searchbar">
<asp:TextBox ID="txtSearch" CssClass="searchbar-field" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" CssClass="searchbar-btn" runat="server" Text="Zoek" OnClick="btnSearch_Click" />
</div>
Run Code Online (Sandbox Code Playgroud)
确定找到了解决方案:需要使用Button
而不是LinkButton
.那应该没问题......
我在这里遇到了问题.我试图使用linq将列表中的项目与另一个列表中的项目进行比较.
例如:
list 1: 10,15,20
list 2: 10,13,14,15,20,30,45,54,67,87
Run Code Online (Sandbox Code Playgroud)
我应该得到TRUE
,如果在所有项目list 1
出现list 2
.所以上面的例子应该返回TRUE
就像你可以看到我无法使用 sequenceEquals
有任何想法吗?
编辑:
list2实际上不是一个列表,它是sql中的列,具有以下值:
<id>673</id><id>698</id><id>735</id><id>1118</id><id>1120</id><id>25353</id>
.
在linq中,由于Jon Skeets的帮助,我做了以下查询:
var query = from e in db
where e.taxonomy_parent_id == 722
select e.taxonomy_item_id;
Run Code Online (Sandbox Code Playgroud)
IQueryable
此刻的查询很长
var query2 = from e in db
where query.Contains(e.taxonomy_item_id)
where !lsTaxIDstring.Except(e.taxonomy_ids.Replace("<id>", "")
.Replace("</id>", "")
.Split(',').ToList())
.Any()
select e.taxonomy_item_id;
Run Code Online (Sandbox Code Playgroud)
但现在我收到了错误Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator
.
在C#ASP.NET中,如果我们在字符串中有字符<或>.我们需要像以下一样逃避:
string a = "\<test\>abcdef\</test\>"
因为这个字符串将通过webservices发送到外部方法.在该方法中,它将被转换为某种xml文件.
contentHtml = "<?xml version=\"1.0\" encoding=\"utf-16\"?>" + contentHtml;
content_ws.AddContent(contentHtml);
//AddContent() method is a external method (via webservices)
Run Code Online (Sandbox Code Playgroud)
例如ô现在转换为Ã'.但我无法访问de Web Service中的代码
谢谢你的帮助
我想在单击HyperLink时触发更新面板更改但是我收到一条错误说:
Control with ID 'X' being registered through RegisterAsyncPostBackControl or RegisterPostBackControl must implement either INamingContainer, IPostBackDataHandler, or IPostBackEventHandler.
Run Code Online (Sandbox Code Playgroud)
如果我使用ASP按钮,那么一切正常
我的代码:
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="UpdateButton2" eventname="Click" />
</Triggers>
<ContentTemplate>
<asp:Repeater ID="rptDossiers" runat="server">
<ItemTemplate>
...
</ItemTemplate>
</asp:Repeater>
<asp:HyperLink NavigateUrl="#" runat="server" id="UpdateButton2" onclick="tousLesDossiers_Click">
Tous les Dossiers
</asp:HyperLink>
<%--<asp:Button runat="server" id="UpdateButton2" onclick="tousLesDossiers_Click" text="Update" />--%>
</ContentTemplate>
</asp:UpdatePanel>
Run Code Online (Sandbox Code Playgroud)
有什么建议?
谢谢
假设我有以下字符串:
string test = " False";
我无法循环字符串的字符,因为我需要为1744字符串执行此操作,那么这将是很多工作.
你知道微软是否有一种方法可以用来删除这个空格?
像这样: string test2 = test.DeleteFirstWhitespace();
谢谢
我有以下JQuery代码
$("#classparent").click(function () {
$(".classsubitems").slideToggle('slow', function () {
});
});
Run Code Online (Sandbox Code Playgroud)
我需要让JQuery在动画的开始和结束时运行一些代码.
这可能吗?
谢谢
考虑下面的html
<ul id="headmenu">
<li id="headmenuitem1"></li>
<li id="headmenuitem2"></li>
<li id="headmenuitem3"></li>
<li id="headmenuitem4"></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
我需要在一个项目上选择所有其他元素.比如我在徘徊headmenuitem1
$(document).ready(function () {
$("#headmenuitem1").hover(function () { //When item is hovered...
$(this).... //(select all the other items)
})
});
Run Code Online (Sandbox Code Playgroud)
在做的时候this
我需要选择所有其他项目,因此在示例中,它必须选择项目headmenuitem2, headmenuitem3 and headmenuitem4
有什么建议?谢谢
asp.net ×10
c# ×8
html ×4
.net ×3
list ×3
forms ×2
javascript ×2
jquery ×2
ajax ×1
arraylist ×1
button ×1
client-side ×1
comparison ×1
escaping ×1
linq ×1
recursion ×1
sql ×1
string ×1
updatepanel ×1
validation ×1
whitespace ×1