I want to insert asp image control inside datalist Itemtemplate through C#. Here is the code below i am currently trying but it didn't work.
DataList DataListCampaign = new DataList();
DataListCampaign.RepeatLayout = RepeatLayout.Flow ;
DataListCampaign.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;
DataListCampaign.DataSource = CampTabImage;
DataListCampaign.DataBind();
Image TabImages = new Image();
TabImages.ID = "TabImages";
DataListCampaign.Controls.Add(TabImages);
TabContainer1.Tabs[k].Controls.Add(DataListCampaign);
Where is the problem??
try with this
Image TabImages = new Image();
TabImages.ID = "TabImages";
TabImages.ImageUrl = "~/imagepath";
DataListCampaign.Items[0].Controls.Add(TabImages);
Related
I am trying to load an image into an Image control in a WPF application.
I need to set the Input in one function, and bind it to the Image in another.
This works:
var b = new Binding { Source = (ImageSource)new ImageSourceConverter().ConvertFromString("D:/data/TestPattern.jpg") };
CameraFrame.SetBinding(Image.SourceProperty, b);
But this does not:
BitmapImage bSource = new BitmapImage(new Uri("D:/data/TestPattern.jpg"));
var b = new Binding { Source = (ImageSource)new ImageSourceConverter().ConvertFrom(bSource) };
CameraFrame.SetBinding(Image.SourceProperty, b);
Why is this? Am I missing something in the ConvertFrom function?
Why don't you simply set the Source property to a BitmapImage?
CameraFrame.Source = new BitmapImage(new Uri("D:/data/TestPattern.jpg"));
I'm new in this field. I'm working in windows application, I create panel and adding the buttons inside the panel. i want to retrieve the image from database and set to the background image in button.
This is my code,
FileName = objDR["Photopath"].ToString();
byte[] data = Encoding.UTF8.GetBytes(FileName);
MemoryStream ms = new MemoryStream(data);
image = new System.Drawing.Bitmap(ms);
Buttons[i].BackgroundImage = image;
initially put BackgroundImage property ON
OR
You can Code :
button1.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.Image));
I'm new to developing with C# and asp.net. I am trying to laod five images onto my web form I also need to do it code behind and not just drag and drop. I can't get them to work. I have tried:
dicePic[i] = new System.Web.UI.WebControls.Image();
//dicePic[0] = Image.FromFile(HttpContext.Current.Server.MapPath("/images/1.gif"));
I also set the properties like this:
dicePic[0].ID = "Dice1";
dicePic[0].Style["position"] = "absolute";
dicePic[0].Style["top"] = "80px";
dicePic[0].Style["left"] = "80px";
dicePic[0].Visible = true;
dicePic[0].Width = 50;
dicePic[0].Height = 50;
dicePic[0].ImageUrl = "~/images/1.gif";//HttpContext.Current.Server.MapPath("/images/1.gif");
dicePic[0].Controls.Add(dicePic[0]);
Any help would be great. Thanks
replace this line :dicePic[0].Controls.Add(dicePic[0]); by this.Controls.Add(dicePic[0]);
You should add it to a container in your page (or to the page itself).
if you are doing this inside a Page put
this.Controls.Add(dicePic[i]);
after
dicePic[i] = new System.Web.UI.WebControls.Image();
I need to load a silverlight application in a portion of an aspx page on a button click on that page page. Some init parameters need to be passed to the silverlight application based on the user inputs on the host page on button click. How to do that?
I presume I need to create the silverlight object from code-behind to set custom InitParameters. Any idea how to do that?
Extending to what is mentioned here, you can do something like this:
HtmlGenericControl myHtmlObject = new HtmlGenericControl("object");
myHtmlObject.Attributes["data"] = "data:application/x-silverlight-2";
myHtmlObject.Attributes["type"] = "application/x-silverlight-2";
myHtmlObject.Attributes["width"] = "100%";
myHtmlObject.Attributes["height"] = "100%";
this.Page.Controls.Add(myHtmlObject);
HtmlGenericControl mySourceParam = new HtmlGenericControl("param");
mySourceParam.Attributes["name"] = "source";
mySourceParam.Attributes["value"] = "ClientBin/MySilverlightApplication.xap";
myHtmlObject.Controls.Add(mySourceParam);
HtmlGenericControl myOnErrorParam = new HtmlGenericControl("param");
myOnErrorParam .Attributes["name"] = "onError";
myOnErrorParam .Attributes["value"] = "onSilverlightError";
myHtmlObject.Controls.Add(myOnErrorParam);
HtmlGenericControl myInputParam = new HtmlGenericControl("param");
myOnErrorParam .Attributes["name"] = "InitParameters";
myOnErrorParam .Attributes["value"] = "param1=Hello,param2=World";
myHtmlObject.Controls.Add(myInputParam);
this.Page.Controls.Add(myHtmlObject);
I want to create an image as a button in code in C# WPF (not a button with BG image but an actual image). I read on this site to use a PictureBox for the image, and I've found that the WPF equivalent is Image. The problem is, that while i've found PictureBox has a .Click that you can set, Image does not. The two things I want to do are:
Create an array of buttons that are images and can be clicked.
Have an image for the unclicked and clicked states of the button.
Is there anything right in front of me I'm missing?
Here is my loop creating the buttons:
sideBarButtons = new Button[infoLoader.categoriesLength];
sideButtons = new Image[infoLoader.categoriesLength];
ImageBrush[] myBg = new ImageBrush[infoLoader.categoriesLength];
for (int i = 0; i < sideBarButtons.Length; i++)
{
myBg[i] = new ImageBrush();
myBg[i].ImageSource = new BitmapImage(graphicLoader.buttonUnselected[(i % myBg.Length)]);
/*sideBarButtons[i] = new Button();
sideBarButtons[i].Content = infoLoader.categories[i].name;
sideBarButtons[i].Background = myBg[i];
//sideBarButtons[i].BorderThickness = ;
sideBarButtons[i].Width = 155;
sideBarButtons[i].Height = 46;
Canvas.SetLeft(sideBarButtons[i], 30);
Canvas.SetTop(sideBarButtons[i], 10 + (46 * i));
sideBarButtons[i].Click += new RoutedEventHandler(this.SideButton_Click);
leftSideBar.Children.Add(sideBarButtons[i]);*/
BitmapImage myBmp = new BitmapImage();
myBmp.BeginInit();
myBmp.UriSource = myBg[i];
myBmp.EndInit();
sideButtons[i] = new Image();
sideButtons[i].Source = myBmp;
sideButtons[i].Width = 155;
sideButtons[i].Height = 46;
Canvas.SetLeft(sideButtons[i], 30);
Canvas.SetTop(sideButtons[i], 10 + (46 * i));
sideButtons[i].Click += new RoutedEventHandler(this.SideButton_Click);
leftSideBar.Children.Add(sideButtons[i]);
}
The first commented out area is when I was creating buttons with buttons and not images, while the second is images and it doesn't work. Thanks in advance.
Two options here:
1.) Instead of using the Click event, which doesn't exist on Image, use MouseDown, which does.
2.) Instead of using Images and repurposing them, use Buttons with a custom style on it. Then you can handle the button's click.
Personally, I'd use the latter, but really either works.