locked
Can you dynamically set the image url in a mobile form mobile image ? RRS feed

  • Question

  • User-1445538092 posted

    I am testing mobile forms, I have created a mobile form with a mobile image.

     <mobile:Image ID="Image6" Runat="server"   ImageUrl="<%#Prodphoto%>" >

     

    I would like to set the image based on the selected value as follows

     private string _prodphoto;
        public string Prodphoto
        {
            get
            {
                return _prodphoto;
            }
            set
            {
                _prodphoto = value;
            }
        }

     

     This is where i set the value

        _prodphoto = "~/Images/" + prod.thumbnail;

     

    This does not seem to work , has anyone any ideas ?

     

    Thanks
     

    Friday, January 11, 2008 5:43 AM

Answers

  • User-2060689755 posted

    Hi Bubbles2,

    You should add the following code to Page_Load event:

    this.DataBind();

    It will work.

    Best regards,
    Guang-Ming Bian - MSFT

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 15, 2008 2:52 AM

All replies

  • User-2060689755 posted

    Hi Bubbles2,

    You should add the following code to Page_Load event:

    this.DataBind();

    It will work.

    Best regards,
    Guang-Ming Bian - MSFT

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 15, 2008 2:52 AM
  • User-1445538092 posted

     Hi

     

    thanks for your reply but it does not work , the main code is below if you have any other idea please

    the section concered is in bold

    or if you have an example of working code 

     

    Thanks 

     ======  Code =======

    public partial class _Default : System.Web.UI.MobileControls.MobilePage
    {
        private System.Collections.Generic.List<CartItem> items;
      
        static ShoppingCart  cart;
        private Order order;
        private Customer cust;
        private string _prodphoto;
        public string Prodphoto
        {
            get
            {
                return _prodphoto;
            }
            set
            {
                _prodphoto = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.DataBind();
        }

     protected void ProductList_ItemCommand(object sender, ListCommandEventArgs e)
        {
            //
            // Called when we select product from list
            //

            if (cart == null)
            {
                cart = new ShoppingCart();
            }
           
            ProductsTableAdapter prodadapt = new ProductsTableAdapter();
            MatrixDB.ProductsDataTable prods = prodadapt.GetByProd(e.ListItem.Value);
            foreach (MatrixDB.ProductsRow prod in prods)
            {
                String pid = prod.productid;
                lblprodid.Text = pid;
                String nam = prod.longtext.Replace(System.Environment.NewLine, " ");
                lblname.Text = nam;
                Decimal pric = prod.price;
                lblprice.Text = pric.ToString();
                String cat = prod.catid;
                txtQty.Text = "1";
                _prodphoto = "~/Images/" + prod.thumbnail;

            }

     ========= ASPX =======

     <mobile:Form id="ProductDetail" runat="server"   >
        <mobile:Image ID="Image3" Runat="server" Font-Size="Small" ImageUrl="~/Images/Matrix.gif">
        </mobile:Image>
          <mobile:Label ID="lblprodid" Runat="server" Visible="False">Label</mobile:Label>
          <br />
          <mobile:Label ID="lblname" Runat="server" Wrapping="Wrap">
          </mobile:Label>
          <br />
                    <mobile:Label ID="lblprice" Runat="server">Price</mobile:Label>
          <br />
          <mobile:TextBox ID="txtQty" Runat="server">
          </mobile:TextBox>
          <br />
          <mobile:Image ID="Image6" Runat="server"   ImageUrl="<%#Prodphoto%>" >
          </mobile:Image>
          <br />
     
        
        <mobile:Command ID="Command3" Runat="server" Text= "<%$ Resources:Resource,mfcont%>" OnClick="Command3_Click" ></mobile:Command>
       
          <mobile:Command ID="Command4" Runat="server"
          Text= "<%$ Resources:Resource,mfretcat%>" OnClick="Command4_Click"></mobile:Command>
         
            <mobile:Command ID="Command5" Runat="server"
          Text= "<%$ Resources:Resource,mfquit%>" OnClick="Command5_Click"></mobile:Command>
          
          </mobile:Form>

     

    Tuesday, January 15, 2008 6:50 AM
  • User-2060689755 posted

    Hi Bubbles2 ,

    Please  keep in mind, you should set  Prodphoto property before invoking this.databind() in page_load, you set the value in ProductList_ItemCommand event, I don't know when does the event fire. You can set a breakpoint at this.databind() line code, where watch Prodphoto property value, you will know the reason.

    Below is a sample , it works fine in my local:

    protected void Page_Load(object sender, EventArgs e)

    {

    this.DataBind();

    }

    private string m_Prodphoto = "~/Image/Image001.jpg";
    public string Prodphoto
    {

    get { return m_Prodphoto; }

    set { m_Prodphoto = value; }

    }

    Best regards,
    Guang-Ming Bian - MSFT

    Wednesday, January 16, 2008 4:19 AM
  • User-1445538092 posted

     Hi Thanks a lot

    I put the Data bind before I set the active form and it works great thanks again.

       this.DataBind();
            ActiveForm = ProductDetail; 

     

    Can you suggest a doucuments which describes the sequence in which events are fired ? 

    [:D] 

    Wednesday, January 16, 2008 1:17 PM
  • User-2060689755 posted

    Hi Bubbles2,

    See following document:
    http://msdn.microsoft.com/en-us/library/aa719775(vs.71).aspx

     

    Best regards,
    Guang-Ming Bian - MSFT

    Thursday, January 17, 2008 3:24 AM