更改DataList中的Label文本

更改DataList中的Label文本

本文介绍了如何更改DataList中的Label文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想更改DataList中的Label文本。我想检查产品库存是否为0,如果库存从0大到通知:有库存,如果库存为0则通知:不可用库存。 我的代码是:I want to change the Label text in my DataList. I want to check whether the product stock is 0 or not, if the stock is large from 0 to notify: Available in stock, if the stock is 0 to notify: Not available stock.My code is:int stock = 0; OleDbConnection con1 = new OleDbConnection(); con1.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("") + "\\Database1.accdb"; con1.Open(); string sqlstring2Stock = "select * from ProductsTable where ProductModel like '%" + search.Text + "%' or ProductManufacturer like '%" + search.Text + "%' or ProductManufacturer + ' ' + ProductModel like '%" + search.Text + "%' order by CatalogNumber"; OleDbCommand Cmd22 = new OleDbCommand(sqlstring2Stock, con1); OleDbDataReader d1r = Cmd22.ExecuteReader(); d1r.Read(); stock = int.Parse(d1r["ProductStock"].ToString()); con1.Close(); if (stock <= 0) { LabelAvailable.Text = "Not available"; } else { LabelAvailable.Text = "Available"; } 我的数据列表是:My DataList is:<asp:DataList ID="DataList1" runat="server" DataKeyField="ProductModel" RepeatDirection="Horizontal" RepeatColumns="5" Width="100%"> <ItemTemplate> <td align="center" > <img src="<%# DataBinder.Eval(Container.DataItem, "ProductImage")%>" height='120' width='150' /><br /> <%# DataBinder.Eval(Container.DataItem, "ProductManufacturer")%> <%# DataBinder.Eval(Container.DataItem, "ProductModel")%><br /> <%# DataBinder.Eval(Container.DataItem, "Price")%> $<%--<br />--%> <asp:Label ID="LabelAvailable" runat="server" Text="Label"></asp:Label><br /> <a href="ShowProductSearch.aspx?Model=<%# DataBinder.Eval(Container.DataItem, "ProductModel")%>">For details</a><br /> <asp:Button ID="AddToCart" runat="server" Text="Add To Cart" /> </td> </ItemTemplate> </asp:DataList> 感谢您的帮助!!!Thanks for your help!!!推荐答案 感谢您的帮助!!!Thanks for your help!!! 这篇关于如何更改DataList中的Label文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-02 05:49