我想讓我的datalist按下按鈕時打開模式彈出窗口。我的問題是數據切換和數據目標不在我的datalist中的asp:Button上工作。但只適用於按鈕,與按鈕的問題是我不能使用CommandArgument,我需要在我的模式上的datalist顯示選擇該項目。我怎樣才能讓我的按鈕在datalist使用命令參數,而不是asp:按鈕
<ItemTemplate>
<div>
<asp:Image CssClass="center-block" Width="200px" Height="200px" ImageUrl='<%# "\\productImages\\" + Eval("productImage") %>' runat="server" />
<br />
<b><%# Eval("ProductName") %></b>
<button id="btnmod" runat="server" type="button" class="btn-success btn-xs pull-right" data-toggle="modal" data-target="#myModal">Buy</button>
<asp:Button data-toggle="modal" data-target="#myModal" CssClass="btn-default pull-right btn-xs" ID="btnBuy" runat="server" Text="Buy" CommandName="Buy" CommandArgument='<%# Eval("productID") %>'/>
<b class="pull-right">$<%#string.Format("{0:n2}",Eval("ProductPrice")) %></b>
<br />
</div>
這是我加載了我的模態的C#代碼:現在如果我按「按鈕」
protected void dlProducts_ItemCommand(object source, DataListCommandEventArgs e)
{
DAL mydal = new DAL(conn);
string productID = Convert.ToString(e.CommandArgument);
mydal.AddParam("productID", productID);
DataSet ds = mydal.ExecuteProcedure("spGetProducts");
lblmodName.Text = ds.Tables[0].Rows[0]["productName"].ToString();
lblmoddescription.Text = ds.Tables[0].Rows[0]["productDescription"].ToString();
modimgprod.ImageUrl = "\\productImages\\" + ds.Tables[0].Rows[0]["productImage"].ToString();
}
它顯示了模態而空,如果我按一下ASP:按鈕它加載數據並將其放入模式中,但不會顯示模式。所以,現在如果你再次按下按鈕,現在它已經填滿了。我一直在做一些研究,也許我可以點擊「按鈕」點擊一個點擊asp:按鈕的事件,但沒有運氣。我卡住了,並會感謝所有的幫助!
This Works!非常感謝! – Marq
很高興幫助!將來,您可能會考慮在Ajax調用的所有客戶端執行此操作,而不是數據列表操作,該操作需要回發並完全重新呈現頁面。這不僅僅是針對這個特定問題的簡單答案 –