如何隐藏asp.net中datalist中的particalr下拉列表 [英] How to hide a particualr drop down list in datalist in asp.net
问题描述
大家好,
我正在显示一些来自数据库的产品,用于在线购物。在数据列表的下拉列表中可用的库存。问题是我想要隐藏添加到购物车按钮并在库存可用时为0下拉库存。所以我尝试在项目数据绑定事件上执行此操作,但它要么隐藏所有ddl,要么隐藏所有ddls。
请给我一个解决方案。这是我的代码:
Hi all,
I am displaying some products from database for online shopping with their no. of stock available in drop down list in a datalist. The problem is I want to hide the add to cart button and drop down of stock if the stock available is 0. So I have tried doing it on item databound event but it either hides all the ddls or hides none.
Kindly give me a solution for it. here is my code:
DataTable dtResult = bl_NecklaceSets.fetching_products_NecklaceSets();
if (dtResult.Rows.Count != 0)
{
for (int i_count = 0; i_count < dtResult.Rows.Count; i_count++)
{
i_out_of_stock_value = Convert.ToInt32(dtResult.Rows[i_count]["Out_Of_stock"]);
if (i_out_of_stock_value == 1)
{
dtResult.Rows[i_count].SetField("Product_Name", (dtResult.Rows[i_count]["Product_Name"]).ToString() + " - Already Sold");
dtResult.AcceptChanges();
DropDownList ddlQuantity = ((DropDownList)(dtlst_Necklace_Sets.NamingContainer.FindControl("dd_quntity")));
string str_quantity = ddlQuantity.SelectedItem.Text.ToString();
;
if (str_quantity == "0")
{
ddlQuantity.Visible = false;
}
else
{
ddlQuantity.Visible = true;
}
}
上面显示的方法是页面加载而不是在数据库中。在数据绑定中,我这样做:
The method above shown is in page load not in databound. In data bound i have done it like this:
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataTable dtResult = bl_NecklaceSets.fetching_products_NecklaceSets();
for (int i_count = 0; i_count < dtResult.Rows.Count; i_count++)
{
i_out_of_stock_value = Convert.ToInt32(dtResult.Rows[i_count]["Out_Of_stock"]);
if (i_out_of_stock_value == 1)
{
DropDownList ddlQuantity = ((DropDownList)(e.Item.FindControl("dd_quntity"))) ;
string str_quantity = Convert.ToString(((DropDownList)(e.Item.FindControl("dd_quntity"))).SelectedItem.Text);
if (str_quantity == "0")
{
ddlQuantity.Visible = false;
}
else
{
ddlQuantity.Visible = true;
}
。
请帮忙!
.
Please help !
推荐答案
嗨Taresh,
您可以使用ItemDataBound事件更新特定项目。
Hi Taresh,
You can use ItemDataBound Event to update a particular item.
<asp:datalist id="" runat="server" onitemdatabound="DataListItemEventHandler" xmlns:asp="#unknown">
</asp:datalist>
proctected void OnRowDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList ddlQuantity = ((DropDownList)(e.Item.FindControl("dd_quntity"))) ;
//Find current value
if (currValue.Equals("0"))
{
ddlQuantity.Visible = false;
}
else
{
ddlQuantity.Visible = true;
}
}
}
嗨Taresh,
使用OnRowDataBound方法更新每一行。
Hi Taresh,
Use OnRowDataBound method to update each row.
proctected void OnRowDataBound(object sender, EventArg e)
{
DropDownList ddlQuantity = ((DropDownList)(e.Item.FindControl("dd_quntity"))) ;
if (ddlQuantity.SelectedItem.Text.Equals("0"))
{
ddlQuantity.Visible = false;
}
else
{
ddlQuantity.Visible = true;
}
}
希望这对你有帮助。
hope this will help you.
HI,我自己在数据绑定上解决了这个问题。我的数据主义者的事件。我只是做了一些条件并遍历了datalist的所有行..如果条件为真,那个特定行'的DDL隐藏其他保持正常。 !
谢谢大家的帮助!
I solved this myself on databound event of my datalist. I just made some condition and iterated through all the rows of the datalist.. if the condition was true than that particular row''s DDL hides else stays normal. !
Thank u all for your help !
这篇关于如何隐藏asp.net中datalist中的particalr下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!