您好,登錄后才能下訂單哦!
如何在datagrid與repeader控件中對標識值進行替換?很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。
DataGrid控件中替換標識值的使用:
<asp:DataGrid ID="dgList" runat="server" Width="100%" AutoGenerateColumns="False"> <Columns> <asp:BoundColumn DataField="COP_G_NO" HeaderText="物料號/成品貨號"></asp:BoundColumn> <asp:BoundColumn DataField="QTY" HeaderText="數量"></asp:BoundColumn> <asp:TemplateColumn HeaderText="物料標識"> <ItemTemplate> <%#GetTransType(DataBinder.Eval(Container.DataItem, "FLAG"))%> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid> 直接調用后臺方法: <asp:TemplateColumn HeaderText="原產地"> <ItemTemplate> <%# (Common.Constant.CountryList.ContainsKey(Eval("COUNTRY") + "")) ? Common.Constant.CountryList[Eval("COUNTRY") + ""] : Eval("COUNTRY") + "" %> </ItemTemplate> </asp:TemplateColumn>
public string GetTransType(object obj) { string type_flag = Convert.ToString(obj); string strReturn = ""; switch (type_flag) { case "1": strReturn = "在廠產品"; break; case "2": strReturn = "在廠半成品"; break; case "3": strReturn = "已出庫未報關成品"; break; case "I": strReturn = "在廠原材料數量"; break; case "Y": strReturn = "已報關未入庫料件數量"; break; case "W": strReturn = "已入庫未報關料件數量"; break; default: ; break; } return strReturn; }
repeader控件中替換標識值的方法:
<asp:Repeater ID="rp_List" runat="server" OnItemCommand="rp_List_ItemCommand"> <ItemTemplate> <tr> <td> <input id="chk" type="checkbox" name="chkName" runat="server" /> </td> <td width="70"> <asp:HyperLink NavigateUrl='<%# getLink(Eval("CodeNameCn"),Eval("Guid"))%>' ID="hl_guid" runat="server"><%# Eval("OrderNo")%></asp:HyperLink> </td> <td> <%# Eval("CustomerNo")%><asp:HiddenField ID="hf_OrderNo" Value='<%# Eval("Guid") %>' runat="server" /> </td> <td> <%# getInOrOut(Eval("IeType"))%> </td> <td> <%# Eval("TradeMode")%> </td> <td> <%# Eval("TotalQuantity")%> </td> <td> <%# Eval("TotalAmount")%> </td> <td> <%# Eval("ShipPeople")%> </td> <td> <%# Eval("ReceivePeople")%> </td> <td> <asp:LinkButton ID="lb_xiadan" runat="server" CommandName="xiadan"><%#getIsShowXiadan(Eval("Status"))%></asp:LinkButton> </td> <td> <%# GetExistService(Eval("HasWMSService"), Eval("HasFreightAgent"), Eval("HasCustomsClearance"))%> </td> <td> <%# Eval("CodeNameCn")%> </td> <td> <%# Convert.ToDateTime(Eval("CreateTime")).ToString("yyyy-MM-dd")%> </td> </tr> </ItemTemplate> </asp:Repeater>
C#后臺方法:
public string getLink(object objStatus, object objGuid) { if (objStatus == null) { return "#"; } else if (objStatus + "" == "未下單") { return "GjmyOrderSave.aspx?guid=" + objGuid; } else { return "GjmyOrderDetail.aspx?guid=" + objGuid; } }
public string GetExistService(object objHasWMSService, object objHasFreightAgent, object objHasCustomsClearance) { string serviceHtml = ""; if (objHasWMSService != DBNull.Value) { if (Convert.ToBoolean(objHasWMSService) == true) { serviceHtml += " 倉庫發貨 "; } } if (objHasFreightAgent != DBNull.Value) { if (Convert.ToBoolean(objHasFreightAgent) == true) { serviceHtml += " 貨運代理 "; } } if (objHasCustomsClearance != DBNull.Value) { if (Convert.ToBoolean(objHasCustomsClearance) == true) { serviceHtml += " 報關報檢 "; } } return serviceHtml; }
看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注億速云行業資訊頻道,感謝您對億速云的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。