0
Answer

hey,I am using DataList to Show Seats where booked by a ImageButton,when i click this button it chan...

Shahid AB

Shahid AB

12y
1.3k
1
hey,I am using DataList to Show Seats where booked by a ImageButton,when i click this button it change to another picture,and the item is add to cart(Grid View),if this item remove from cart,it dose not change to previous image.how can i do?please details me in C# code in ASP.NET4.


Source Code :

 <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSourceList"
         RepeatColumns="4" BorderColor="#CC6600" BorderWidth="0.1em"
         GridLines="Both" DataKeyField="SeatID" onitemcommand="DataList1_ItemCommand">
      <ItemTemplate>
      <table class="style1">
         <tr>
             <td>
                 Seat ID :</td>
             <td>
                 <asp:Label ID="lblSID" runat="server" Text='<%#Eval("SeatID") %>'></asp:Label>
             </td>
         </tr>
         <tr>
             <td>
                 Seat Status :</td>
             <td>
                 <asp:Label ID="lblStatus" runat="server" Text='<%#Eval("SeatStatus") %>'></asp:Label>
             </td>
         </tr>
         <tr>
             <td>
                 &nbsp;</td>
             <td>
                 &nbsp;</td>
         </tr>
         <tr>
             <td colspan="2">
                 <asp:ImageButton ID="BtnBook" runat="server" ImageUrl="~/Icons/Tick.jpg"
                     CommandName="Book" />
             </td>
         </tr>
     </table>
     </ItemTemplate>
 </asp:DataList>
     <asp:SqlDataSource ID="SqlDataSourceList" runat="server"
         ConnectionString="<%$ ConnectionStrings:ATRConString %>"
        
         SelectCommand="SELECT [SeatID], [SeatStatus] FROM [vwSeatShow] WHERE (([SCatID] = @SCatID) AND ([SeatStatus] = @SeatStatus))">
         <SelectParameters>
             <asp:ControlParameter ControlID="DropDownListSeatCat" Name="SCatID"
                 PropertyName="SelectedValue" Type="Int32" />
             <asp:Parameter DefaultValue="Available" Name="SeatStatus"
                 Type="String" />
         </SelectParameters>
     </asp:SqlDataSource>

C Sharp Code :

   protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "Book")
        {
            Label lblId = (Label)DataList1.Items[e.Item.ItemIndex].FindControl("lblSID");


            Label1.Text = lblId.Text;

            btn = (ImageButton)DataList1.Items[e.Item.ItemIndex].FindControl("BtnBook");
            btn.ImageUrl = "~/Icons/Cros.jpg";

            AddSeatToCart();

            gvCart.DataSource = dt;
            gvCart.DataBind();

        }
    }
    protected void gvCart_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        dt.Rows.RemoveAt(e.RowIndex);
        gvCart.DataBind();

        //btn = (ImageButton)DataList1.FindControl("BtnBook");
        //btn.ImageUrl = "~/Icons/Tick.jpg";
    }