我有这段代码:
<div class="detailBox">
<div class="actionBox">
<ul class="commentList">
<%
foreach (System.Data.DataRow drow in members.Rows)
{
%>
<li>
<div class="commentText">
<span><%= drow["nume_user"] %></span>
<asp:Button ID="deleteButton" CssClass="btn btn-danger btn-xs" runat="server" OnClick="deleteMember" Text="Elimina" CommandArgument="<%= drow["id"] %>" />
</div>
</li>
<%
}
%>
</ul>
</div>
</div>
我不知道为什么当我想Server tags cannot contain <% ... %> constructs.
给CommandArgument
drow["id"]
时,我会收到此错误 protected void deleteMember(object sender, EventArgs e)
{
String connString = System.Configuration.ConfigurationManager.ConnectionStrings["GroupsConnString"].ToString();
var argument = ((Button)sender).CommandArgument;
Response.Write(argument);
if (argument != null)
{
MySqlConnection conn = new MySqlConnection(connString);
conn.Open();
MySqlCommand comm = conn.CreateCommand();
comm.CommandText = "DELETE FROM app_groups.users_groups_leg WHERE id = " + argument;
int result = comm.ExecuteNonQuery(); //here you will get the no.of rows effected
conn.Close();
}
}
,当我点击时如何将此变量传递给后面的代码在按钮上?
EDIT 当我点击按钮时,正在执行的代码:
String trpname="<?xml version='1.0' encoding='UTF-8'?><root available-locales='bg_BG,cs_CZ,de_DE,el_GR,en_GB,es_ES,es_MX,fr_FR,hr_HR,hu_HU,in_ID,it_IT,ja_JP,ko_KR,pl_PL,pt_BR,pt_PT,ro_RO,ru_RU,sk_SK,tr_TR,zh_CN,zh_TW' default-locale='en_US'>"
+" <name language-id='bg_BG'>ISV OEM и Препродажба</name>"
+" <name language-id='cs_CZ'>ISV OEM a prodej</name>"
+" <name language-id='de_DE'>ISV, OEM & Wiederverkauf</name>"
+" <name language-id='el_GR'>ISV OEM & Μεταπωλητές</name>"
+" <name language-id='en_GB'>ISV OEM & Resell</name>"
+" <name language-id='es_ES'>OEM de ISV y Distribución</name>"
+" <name language-id='es_MX'>ISV OEM y Reventa</name>"
+" <name language-id='fr_FR'>OEM ISV et revente</name>"
+" <name language-id='hr_HR'>ISV proizvođač originalne opreme i preprodaja</name>"
+" <name language-id='hu_HU'>ISV OEM és viszonteladó</name>"
+" <name language-id='in_ID'>OEM ISV OEM & Penyaluran</name>"
+" <name language-id='it_IT'>Rivenditori e OEM ISV</name>"
+" <name language-id='ja_JP'>ISV OEMおよび再販</name>"
+" <name language-id='ko_KR'>ISV OEM 및 리셀</name>"
+" <name language-id='pl_PL'>ISV OEM i sprzedaż</name>"
+" <name language-id='pt_BR'>OEM & Revenda de ISV</name>"
+" <name language-id='pt_PT'>ISV OEM e Revenda</name>"
+" <name language-id='ro_RO'>OEM şi revânzare ISV</name>"
+" <name language-id='ru_RU'>Услуги независимых OEM-поставщиков ПО</name>"
+" <name language-id='sk_SK'>ISV OEM a predaj</name>"
+" <name language-id='tr_TR'>ISV OEM ve Satış</name>"
+" <name language-id='zh_CN'>ISV OEM 和转售</name>"
+" <name language-id='zh_TW'>ISV OEM 與經銷</name>"
+" <name language-id='en_US'>ISV OEM & Resell</name>"
+"</root>";
String translatedProgramName = HtmlUtil.unescape(trpname);
String programName = LocalizationUtil.getLocalization(translatedProgramName, "en_US");
答案 0 :(得分:1)
我认为您应该使用<%# %>
在c#和html之间切换。所以你的代码应该是
<div class="detailBox">
<div class="actionBox">
<ul class="commentList">
<%#
foreach (System.Data.DataRow drow in members.Rows)
{
%>
<li>
<div class="commentText">
<span><%= drow["nume_user"] %></span>
<asp:Button ID="deleteButton" CssClass="btn btn-danger btn-xs" runat="server" OnClick="deleteMember" Text="Elimina" CommandArgument="<%= drow["id"] %>" />
</div>
</li>
<%#
}
%>
</ul>
</div>
</div>