【发布时间】:2017-05-12 23:53:34
【问题描述】:
我正在尝试使用列表框项更新表格。我遇到错误“int”不包含“Items”的定义,并且找不到接受“int”类型的第一个参数的扩展方法“Items”(您是否缺少 using 指令或程序集引用?)
感谢您的帮助
HTML
<asp:ListBox ID="lbSampleID" runat="server" Height="99px" Width="131px"> </asp:ListBox>
<input type="button" id="btnUpdateConsent" value="Update Consent" onclick="updateConsent();" class="auto-style142" />
JavaScript
<script type="text/javascript">
function updateConsent() {
var SampleID = document.getElementById("lbSampleID").value;
xmlhttp.open("GET", "UpdateConsent.aspx?mb=" + MBID + " &ci= " + ConsentID + "&cd=" + ConsentDate +
"&wd=" + WithdrawDate + "&cw=" + ConsentWithdraw + "&ncn=" + NewConsentName + "&si=" + SampleID, false);
xmlhttp.send(null);
}
C#
string lbSampleID = Request.QueryString["si"].ToString();
using (SqlCommand sc = new SqlCommand(@"Update Sample
set ConsentConfirmed='NO' , DateConsent='', ConsentNameID=@NewConsentName
WHERE MBID = @MBID and ConsentNameID = @ConsentID and SampleID=@SampleID", con))
{
sc.Parameters.Add("@MBID", SqlDbType.Int).Value=MBID;
sc.Parameters.Add("@ConsentID", SqlDbType.Int).Value = ConsentID;
sc.Parameters.Add("@NewConsentName", SqlDbType.Int).Value = NewConsentName;
int records = sc.ExecuteNonQuery();
int value = records;
int ListBox1 = Convert.ToInt32(lbSampleID);
// Error with the loop
foreach (ListItem item in ListBox1.Items)
{
if (item.Selected)
{
try
{
sc.Parameters["@SampleID"].Value = item.Text;
sc.ExecuteNonQuery();
}
catch (Exception ex)
{
// Label1.Text = ex.Message;
}
}
}
}
【问题讨论】:
-
为了将来的参考,请参阅这篇关于创建Minimal, Complete, and Verifiable 示例的文章来说明您面临的问题。您发布的大部分代码与您的问题无关。
标签: c# asp.net sql-server