1
我試圖創建一個嵌套的Repeaters。Asp.net/C#:將客戶ID傳遞給函數中的Linq查詢
我有我的觀點的文章
我做到了在本指南正確地創建代碼,但有客戶ID傳遞給函數的一個問題。
我將通過代碼解釋它,我的.aspx代碼:
<asp:Repeater ID="rptCustomers" runat="server" OnItemDataBound="rptCustomers_ItemDataBound">
<HeaderTemplate>
<table class="table table-hover table-striped table-condensed table-bordered table-responsive" >
<tr>
<th>
</th>
<th>
Deposit Number
</th>
<th>
Custom Declaration
</th>
<th>Category</th>
<th>Location</th>
<th>Goods Description</th>
<th>Units Balance</th>
<th>WT Balance</th>
<th>Goods Balance Amount(LC)</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<img alt="" style="cursor: pointer" src="images/plus.png" />
<asp:Panel ID="pnlOrders" runat="server" Style="display: none">
<asp:Repeater ID="rptOrders" runat="server">
<HeaderTemplate>
<table class="table table-hover table-striped table-condensed table-bordered table-responsive" >
<tr>
<th>
Item No
</th>
<th>
Item descr
</th>
<th>
UOM
</th>
<th>
Balance Units
</th>
<th>
Balance LC
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# Eval("itemNo") %>
</td>
<td>
<%# Eval("itemDesc") %>
</td>
<td>
<%# Eval("Uom") %>
</td>
<td>
<%# Eval("balUnits") %>
</td>
<td>
<%# Eval("balLc") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
<asp:HiddenField ID="hfCustomerId" runat="server" Value='<%# Eval("depID") %>' />
</td>
<td>
<%# Eval("depNo") %>
</td>
<td>
<%# Eval("customDec") %>
</td>
<td><%#Eval("category") %></td>
<td><%#Eval("location") %></td>
<td><%#Eval("goodDesc") %></td>
<td><%#Eval("unitsBal") %></td>
<td><%#Eval("wtBal") %></td>
<td><%#Eval("lcBal") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
現在這是隱藏字段,將開展客戶ID:
<asp:HiddenField ID="hfCustomerId" runat="server" Value='<%# Eval("depID") %>' />
這是page_load中父代轉發器的代碼:
protected void Page_Load(object sender, EventArgs e)
{
var query = (from cd in db.CDIndexes
join com in db.Companies on cd.cdin_CompanyId equals com.Comp_CompanyId
join ter in db.Territories on cd.cdin_Secterr equals ter.Terr_TerritoryID
where cd.cdin_Deleted == null &&
com.Comp_Deleted == null &&
cd.cdin_Status == "InProgress" &&
com.Comp_CompanyId == 408
select new
{
depID=cd.cdin_CDIndexID,
location = ter.Terr_Caption,
depNo = cd.cdin_Serial,
customDec = cd.cdin_Customdeclar,
category = cd.cdin_category,
goodDesc = cd.cdin_goodsDesc,
unitsBal = cd.cdin_RemainPackages,
wtBal = cd.cdin_RemainWT,
lcBal = cd.cdin_ActMortgageAmnt,
}
).ToList();
rptCustomers.DataSource = query;
rptCustomers.DataBind();
}
這是的ItemDataBound父中繼轉發
protected void rptCustomers_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
var queryItems = (from cd in db.CDIndexes
join com in db.Companies on cd.cdin_CompanyId equals com.Comp_CompanyId
join terr in db.Territories on cd.cdin_Secterr equals terr.Terr_TerritoryID
join gds in db.Goods on cd.cdin_CDIndexID equals gds.good_CDIndexId
join itms in db.Items on gds.good_ItemsID equals itms.item_ItemsID
join capt in db.Custom_Captions on gds.good_UOM equals capt.Capt_Code
where
capt.Capt_Family== "good_UOM" &&
cd.cdin_Deleted == null &&
cd.cdin_Status== "InProgress" &&
cd.cdin_CompanyId==408 &&
cd.cdin_CDIndexID== 2506542 &&
itms.item_Deleted == null &&
cd.cdin_GoodsProperty=="01" &&
com.Comp_Deleted== null
select new
{
itemNo=itms.item_itemNo,
itemDesc=itms.item_Name,
Uom=capt.Capt_US,
balUnits=gds.good_RemainWT,
balLc=gds.good_BalanceAmtLC,
}
).ToList();
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
string customerId = (e.Item.FindControl("hfCustomerId") as HiddenField).Value;
Repeater rptOrders = e.Item.FindControl("rptOrders") as Repeater;
rptOrders.DataSource = queryItems;
rptOrders.DataBind();
}
}
我要的是如何將客戶的ID值傳遞到LINQ查詢,特別是通的,而不是在數(2506542)的ID下面的語句:
cd.cdin_CDIndexID== 2506542
,所以我需要更換中繼器的數據源下面的代碼:
rptOrders.DataSource = queryItems;
rptOrders.DataBind();
與參數字符串客戶ID值 函數調用作爲一個例子:
rptOrders.DataSource = function(customerId);
rptOrders.DataBind();
那是什麼將返回一個LINQ查詢函數的語法。
非常感謝你這解決了這個問題 –