リストビューの単一項目のリストビューitemtemplate item asp.net

アイテムテンプレートとして Addtocart というイメージボタンが含まれている、
recent_all_albums という名前のリストビューがあり、選択したアイテムだけが非表示になりたい。
どうやってするか?

私の.aspx:


    <div style="float: left; width: 988px;">
        <table>
            <tr>
                <td style="width: 960px">
                    <div style="margin-top: 8px; border-bottom: 2px solid #DDDDDD; margin-bottom: 10px;">
                        Featured Pictures 
                    </div>
                    
                        
                            <td id="Td1" runat="server" />
                        
                        
                            <div class="PictureBlock1">
                                <div>
                                    
                                    
                                </div>
                                <div class="PictureBlockButton1">
                                    
                                    
                                </div>
                            </div>
                        
                        
                            <table id="Table1" runat="server">
                                <tr>
                                    <td>
                                        No data was returned.
                                    </td>
                                </tr>
                            </table>
                        
                        
                            <div id="groupPlaceholderContainer" runat="server" class="PictureBlockContainer1">
                                <div id="groupPlaceholder" runat="server">
                                </div>
                            </div>
                            <div id="dvPager" class="header">
                                
                                    
                                        
                                    
                                
                            </div>
                        
                        
                            <div id="itemPlaceholderContainer" runat="server">
                                <div id="itemPlaceholder" runat="server">
                                </div>
                            </div>
                        
                        
                            <div id="Div3" runat="server" style="background-color: #E2DED6; font-weight: bold;
                                color: #333333;">
                            </div>
                        
                    
                </td>
            </tr>
        </table>
        
            
                
            
            
            
        
    </div>

私の.cs:

namespace PicArchieving.UI
{
    public partial class WebForm4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Recent_Albums_All.DataBind();
                Recent_Albums_All.Dispose();
            }
            DataTable Cart = (DataTable)Session["selectedPictureObject1"];
        }

        protected void OnselectCallMethod(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            User aUser;
            if (Session["LoggedUser"] != null)
                aUser = (User)Session["LoggedUser"];
            else
            {
                aUser = new User();
                aUser.UserID = null;
            }
            e.InputParameters["aUser"] = aUser;
        }

        protected void Recent_Albums_SelectedIndexChanged(object sender, EventArgs e)
        {
            PictureManager aManager = new PictureManager();
            Picture aPicture = new Picture();
            aPicture.ID = Convert.ToInt32(((ListView)sender).SelectedDataKey["ID"]);
            Session["selectedPictureObject"] = aPicture;
            objDSPictureViewAll.DataBind();
        }

        protected void Recent_Albums_All_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName == "AddToCart")
            {
                DataTable Cart = Session["selectedPictureObject1"] == null ? new DataTable() : (DataTable)Session["selectedPictureObject1"];
                if (Cart.Columns.Count > 0)
                {

                    try
                    {
                        Cart.Rows.Add(e.CommandArgument.ToString());
                        //want to invisible ImageButtonAddToCart for that listview item
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("This Item Already Exists In Cart");
                    }

                }
                else
                {
                    DataColumn[] key = new DataColumn[1];
                    DataColumn id = new DataColumn();
                    Cart.Columns.Add(id);
                    id.ColumnName = "ID";
                    key[0] = id;
                    Cart.PrimaryKey = key;
                    Cart.Rows.Add(e.CommandArgument.ToString());

                }
                Session["selectedPictureObject1"] = Cart;
                Button btn = (Button)Master.FindControl("ViewCart");
                btn.CssClass = "viewCartFull";
                btn.Visible = true;
            }
        }
    }
}
ベストアンサー

.aspxで:


in .cs:

 protected void Recent_Albums_All_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            int index = Convert.ToInt32(e.CommandArgument);

            if (e.CommandName == "AddToCart")
            {
               ((ImageButton)Recent_Albums_All.Items[index].FindControl("ImageButtonAddToCart")).Visible = false;
            }

        }

コメントする

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です