Jump to content
aic007

How to use image as button?

Recommended Posts

Hi all.I have a question regarding a button, which I have made in visual studio.knappcu8.jpgThe code is:Button button;Label lblSearch = new Label();txtSearch = new TextBox();button = new Button();button.Click += new EventHandler(button_Click);button.Text = "Søk";I have an image, named buttonImage, which I want to use instead of custom text. How can I accomplish that?Regards.

Share this post


Link to post
Share on other sites

Thanks for the answer. I have another question, how can I decide the size of my fields in a gridview?To format the rows I use this code: this.gridView.RowStyle.CssClass="oddetallslinjer";but I don't know how to format the cells.. any ideas?

Share this post


Link to post
Share on other sites
Thanks for the answer. I have another question, how can I decide the size of my fields in a gridview?To format the rows I use this code: this.gridView.RowStyle.CssClass="oddetallslinjer";but I don't know how to format the cells.. any ideas?
If you want to change the size, for example, you can do as follows:this.gridview.RowStyle.Width = "100"this.gridview.RowStyle.Height = "200"(= size in pixels)or make a class in your stylesheet:.oddetallslinjer { background-color: Blue; }etc

Share this post


Link to post
Share on other sites
If you want to change the size, for example, you can do as follows:this.gridview.RowStyle.Width = "100"this.gridview.RowStyle.Height = "200"(= size in pixels)or make a class in your stylesheet:.oddetallslinjer { background-color: Blue; }etc
Hi Emiel.Thanks for answering.I get my fields like this:this.gridView.Columns.Add(GetColumn("Mobil nr, arbeid", null, "Mobil", true, true));From this code I will get "Mobil nr" displayed as the text of the field. Is there a way to specify the size of this field only?:-)

Share this post


Link to post
Share on other sites

Thanks. I'll look at it. :-)I have another question though. I used the ImageButton control to use a picture from css - file as a button, and it works, but I get a red cross on the button also in addition. The red cross looks like a red cross that you see when you are on a web site and can't see a picture.This is my code:ImageButton imgBtn;imgBtn = new ImageButton();imgBtn.Click += new ImageClickEventHandler(imgBtn_Click);imgBtn.CssClass = "SokKnappBilde";I suspect it has something to do with me not having defined any picture paths in this code, but do I need to do that?Is there a way to get rid of that red cross?This is how the button looks like. (see picture on the left)utennavnfk5.jpg

Share this post


Link to post
Share on other sites
Thanks. I'll look at it. :-)I have another question though. I used the ImageButton control to use a picture from css - file as a button, and it works, but I get a red cross on the button also in addition. The red cross looks like a red cross that you see when you are on a web site and can't see a picture.This is my code:ImageButton imgBtn;imgBtn = new ImageButton();imgBtn.Click += new ImageClickEventHandler(imgBtn_Click);imgBtn.CssClass = "SokKnappBilde";I suspect it has something to do with me not having defined any picture paths in this code, but do I need to do that?Is there a way to get rid of that red cross?This is how the button looks like. (see picture on the left)utennavnfk5.jpg
Yes try doing the same thing with a regular Button and ImageButton requires you to specify an image

Share this post


Link to post
Share on other sites

Hi.I have tried with a regular button, but it doesn't look good. utennavnuw3.jpgIt looks like an image attached on a button, but I want it to use image only as button. Any ideas how I can accheive that? This is my code:Button btn;btn = new Button();btn.Click += new EventHandler(btn_Click);btn.Text = "Søk";btn.CssClass = "SokKnappBilde";css:.SokKnappBilde{ float:left; margin:-22px 285px -3px 240px; background-image:url('../../../images/knapp-sok.PNG'); width:75px; height:20px;}:-)

Share this post


Link to post
Share on other sites

Hi again.I solved the problem by using ImageButton and then giving it an imageurl. imgBtn.CssClass = "SokKnappBilde";imgBtn.ImageUrl = "../../../knapp-sok.PNG";.SokKnappBilde{ float:left; margin:-24px 285px -3px 240px; width:75px; height:22px;}Thanks alot for giving me tips. Your assistance is most appreciated. I have another problem though, which I need to sort out. A problem regarding gridview.I get data from SQL, and need to decide the width of my columns, I want my cells to have static widht.This is my code:protected override void CreateChildControls(){try{this.gridView = new GridView();this.gridView.PageSize = 60;this.gridView.AllowSorting = true;this.gridView.AutoGenerateColumns = false;this.gridView.Sorting += new GridViewSortEventHandler(Grid_Sorting); this.gridView.PageIndexChanging += new GridViewPageEventHandler(gridView_PageIndexChanging);this.gridView.RowDataBound += new GridViewRowEventHandler(gridView_RowDataBound);/*Here I get my fields, and I want to change the width of theese fields*/this.gridView.Columns.Add(GetColumn("adresse", null, "Adresse", true, true));this.gridView.Columns.Add(GetColumn("telefon", null, "Tlf", true, true));//TableTable tbl = new Table();TableRow row1 = new TableRow();TableRow row2 = new TableRow();TableCell cell1 = new TableCell();TableCell cell2 = new TableCell();tbl.Controls.Add(row1);row1.Controls.Add(cell1);tbl.Controls.Add(row2);row2.Controls.Add(cell2);this.Controls.Add(tbl);}Any tips for me :-)Regards.

Share this post


Link to post
Share on other sites

you have to set the width of the columns in the RowDataBound event handler

//something likee.Item.Cells[index].Width = 100;

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...