gpt4 book ai didi

c# - 单击上传按钮时无法在数据列表中找到 ID

转载 作者:行者123 更新时间:2023-11-30 18:15:55 24 4
gpt4 key购买 nike

我有一个页面正在使用更新面板、数据列表和文件上传。 我正在使用 visual studio 2010

我的文件上传在数据列表中,我正在将数据列表与动态表绑定(bind)以重复文件上传控制。

请看下面的布局图:

enter image description here

这里 Main 上部红色突出显示的边框显示重复的数据列表,并且我有文件上传控制。

现在数据列表在更新面板中,所以文件上传不起作用所以在数据列表中我使用了另一个更新面板来使文件上传工作并且它也可以正常工作但是点击绿色添加按钮问题开始出现为

A control with ID 'Upload' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.

下面是我的 html 代码,请记住我只是给出了出现问题的部分:

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="Uppanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DataList ID="dtcustomerregistration" runat="server" RepeatDirection="Vertical"
Width="100%" OnItemCommand="dtcustomerregistration_ItemCommand">
<ItemTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<label class="col-md-4 control-label" for="Pic">
Upload Image:</label>

<asp:FileUpload ID="Pic" runat="server" accept="image/gif, image/jpg, image/jpeg, image/png" />

<asp:Button ID="Upload" CommandArgument='<%#Eval("uniqueId") %>' CommandName="Edit"
runat="server" Text="Upload" OnClick="Upload_Click" />
<asp:Label ID="StatusLabel" runat="server" CssClass="requiredvalidate" Text=""></asp:Label>
<asp:HiddenField ID="hdimagename" runat="server" Value='<%#Eval("UploadImage") %>' />

<asp:Image ID="imgpicuploaded" runat="server" ImageUrl='<%#System.Configuration.ConfigurationManager.AppSettings["ShowImagetemppath"].ToString().Replace("~/","") +Eval("UploadImage").ToString() %>'
Height="50px" />
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Upload" />
</Triggers>
</asp:UpdatePanel>
</ItemTemplate>
</asp:DataList>
<asp:ImageButton ID="imgplus" runat="server" ImageUrl="~/Image/Add.png" Height="50px" OnClick="imgplus_Click" />
</ContentTemplate>
</asp:UpdatePanel>

我的 imgplus 点击事件代码如下。

protected void imgplus_Click(object sender, ImageClickEventArgs e)
{
int n = (int)ViewState["n"];
n = n + 1;
BindData(n);
}

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["data"] = null;
BindData(0);
}
}
public void BindData(int n)
{
DataTable dt = new DataTable();
dt.Columns.Add("uniqueId");
dt.Columns.Add("Invoice");
dt.Columns.Add("ReturnType");
dt.Columns.Add("ItemNumber");
dt.Columns.Add("ReturnQTY");
dt.Columns.Add("UnitofMeasure");
dt.Columns.Add("CreditPer");
dt.Columns.Add("ReasonCode");
dt.Columns.Add("InvoiceNumber");
dt.Columns.Add("Ordernumber");
dt.Columns.Add("Notes");
dt.Columns.Add("UploadImage");

if (ViewState["data"] == null)
{
dt = bindemptydata(dt, n);
}
else
{
foreach (DataListItem dli in dtcustomerregistration.Items)
{
HiddenField lblid = (HiddenField)dli.FindControl("lblid");
DropDownList RetCred = (DropDownList)dli.FindControl("RetCred");
DropDownList returntype = (DropDownList)dli.FindControl("returntype");
TextBox ItemNumber = (TextBox)dli.FindControl("ItemNumber");
TextBox ReturnQty = (TextBox)dli.FindControl("ReturnQty");
DropDownList Unit = (DropDownList)dli.FindControl("Unit");
TextBox Credit = (TextBox)dli.FindControl("Credit");
DropDownList ReasonCode = (DropDownList)dli.FindControl("ReasonCode");
TextBox Invoice = (TextBox)dli.FindControl("Invoice");
TextBox OrderNumber = (TextBox)dli.FindControl("OrderNumber");
TextBox Notes = (TextBox)dli.FindControl("Notes");
Image imgpicuploaded = (Image)dli.FindControl("imgpicuploaded");
HiddenField hdimagename = (HiddenField)dli.FindControl("hdimagename");
DataRow dr = dt.NewRow();

if (lblid.Value != "")
{
dr["uniqueId"] = lblid.Value;
}
else
{
dr["uniqueId"] = n;
}
dr["Invoice"] = RetCred.SelectedValue;
dr["ReturnType"] = returntype.SelectedValue;
dr["ItemNumber"] = ItemNumber.Text;
dr["ReturnQTY"] = ReturnQty.Text;
dr["UnitofMeasure"] = Unit.SelectedValue;
dr["CreditPer"] = Credit.Text;
dr["ReasonCode"] = ReasonCode.SelectedValue;
dr["InvoiceNumber"] = Invoice.Text;
dr["Ordernumber"] = OrderNumber.Text;
dr["Notes"] = Notes.Text;
dr["UploadImage"] = hdimagename.Value;
dt.Rows.Add(dr);
}

dt = bindemptydata(dt, n);
}
BindDatalist(dt);
ViewState["n"] = n;
}

public DataTable bindemptydata(DataTable dt, int n)
{
DataRow dr = dt.NewRow();
dr["uniqueId"] = n;
dr["Invoice"] = "Credit";
dr["ReturnType"] = "0";
dr["ItemNumber"] = "";
dr["ReturnQTY"] = "";
dr["UnitofMeasure"] = "Each";
dr["CreditPer"] = "100%";
dr["ReasonCode"] = "0";
dr["InvoiceNumber"] = "";
dr["Ordernumber"] = "";
dr["Notes"] = "";
dr["UploadImage"] = "";
dt.Rows.Add(dr);

return dt;
}
public void BindDatalist(DataTable dt)
{
dtcustomerregistration.DataSource = dt;
dtcustomerregistration.DataBind();// Here I am receiving error
ViewState["data"] = dt;
}

我在上面给出了创建动态数据表并将其与数据列表绑定(bind)的完整代码,以便在单击 imgplus 按钮时重复数据列表但是在点击按钮时我收到错误信息:

下面是错误图片。 enter image description here

我该如何解决这个问题?

单击 Imgplus 按钮时,我收到了 DataList 中存在的上传按钮的问题。

还有一件事,如果我通常单击 ImgPlus 按钮而不使用上传按钮单击,那么它将重复 DataList 控件而不会出现任何问题,但以防万一我使用了上传单击按钮存在于 DataList 中,然后在我单击 Imgplus 按钮后收到错误消息:

A control with ID 'Upload' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.

最佳答案

用另一个 UpdatePanel upButton 包围您的按钮:

<asp:UpdatePanel ID="upButton" runat="server" UpdateMode="Conditional">
<asp:Button ID="Upload" CommandArgument='<%#Eval("uniqueId") %>' CommandName="Edit"
runat="server" Text="Upload" OnClick="Upload_Click" />
</ContentTemplate>

然后在按钮点击方法 Upload_Click 中调用主 UpdatePanel Uppanel.Update();

注意:删除更新面板ID="UpdatePanel1"

关于c# - 单击上传按钮时无法在数据列表中找到 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47453374/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com