如何在运行时数组字符串替换行ID? [英] How to replace row id with array string at runtime?
本文介绍了如何在运行时数组字符串替换行ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
设计code
< TR ID =DEPB=服务器>< / TR>< TR ID =DEPB=服务器>< / TR>< TR ID =DEPB=服务器>< / TR>
code背后
字符串测试= ddlExim.SelectedItem.Text.Substring(3);
txtEximDesc.Text = ddlExim.SelectedItem.Text.Substring(3);
字符串[] =演示ddlExim.SelectedValue.Split('');
尝试
{
DBK.Style.Add(显示,无);
DEPB.Style.Add(显示,无);
EPCG.Style.Add(显示,无);
NFEI.Style.Add(显示,无);
的for(int i = 0;我3;;我++)
{
如果(演示[I] ==DEPB)
{
演示[I] .Style.Add(显示,表行);
}
否则,如果(演示[I] ==EPCG)
{
EPCG.Style.Add(显示,表行);
}
否则,如果(演示[I] ==DBK)
{
DBK.Style.Add(显示,表行);
}
否则,如果(演示[I] ==)。
{
NFEI.Style.Add(显示,表行);
}
}
}
赶上(异常前)
{
字符串消息= ex.Message;
}
我要替换DEPB,EPCG,DBK与演示[I]
象下面,但得到的错误:字符串犯规包含defnition样式
演示[I] .Style.Add(显示,表行);
解决方案
标记 =服务器
表元素中这些tablerows是present( TBL在我的例子),然后尝试以下code。
的for(int i = 0; I< Demo.Length;我++)
{
(tbl.FindControl(演示[I])作为HtmlTableRow).Style.Add(显示,表行);
}
当然,你需要添加以下命名空间。
使用System.Web.UI.HtmlControls;
希望这有助于。
Design Code
<tr id="DEPB" runat="server"></tr>
<tr id="DEPB" runat="server"></tr>
<tr id="DEPB" runat="server"></tr>
Behind Code
string Test = ddlExim.SelectedItem.Text.Substring(3);
txtEximDesc.Text = ddlExim.SelectedItem.Text.Substring(3);
string[] Demo = ddlExim.SelectedValue.Split(',');
try
{
DBK.Style.Add("display", "none");
DEPB.Style.Add("display", "none");
EPCG.Style.Add("display", "none");
NFEI.Style.Add("display", "none");
for (int i = 0; i < 3; i++)
{
if (Demo[i] == "DEPB")
{
Demo[i].Style.Add("display", "table-row");
}
else if (Demo[i] == "EPCG")
{
EPCG.Style.Add("display", "table-row");
}
else if (Demo[i] == "DBK")
{
DBK.Style.Add("display", "table-row");
}
else if (Demo[i] == ".")
{
NFEI.Style.Add("display", "table-row");
}
}
}
catch (Exception ex)
{
string Message = ex.Message;
}
i want to replace DEPB,EPCG,DBK with Demo[i]
like below but getting error: "String doesnt contain a defnition for style".
Demo[i].Style.Add("display", "table-row");
解决方案
Mark runat="server"
to the table element inside which these tablerows are present ("tbl" in my example) and then try the following code.
for (int i = 0; i < Demo.Length; i++)
{
(tbl.FindControl(Demo[i]) as HtmlTableRow).Style.Add("display", "table-row");
}
Of course you need to add the following namespace.
using System.Web.UI.HtmlControls;
Hope this helps.
这篇关于如何在运行时数组字符串替换行ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文