Jump to content
Sign in to follow this  
v1tal1ty

Asp:ImageButton dentro de uma gridview não visível

Recommended Posts

v1tal1ty

Boas,

venho mais uma vez apresentar a minha duvida a este grande fórum.

Trata se de um site de partilha de ficheiros.

aqui tenho a tabela:

		 DataTable table = new DataTable();
		 table.Columns.Add(new DataColumn("Título do documento", typeof(string)));
		 table.Columns.Add(new DataColumn("Nome", typeof(string)));
		 table.Columns.Add(new DataColumn("Data de criação", typeof(string)));
		 table.Columns.Add(new DataColumn("Tamanho", typeof(string)));
		 table.Columns.Add(new DataColumn("Tipo de documento", typeof(string)));
		 table.Columns.Add(new DataColumn("Formato", typeof(string))); // este campo so é preenchido mais tarde.

Tenho uma gridview assim:

	 <asp:GridView ID="GridView1" runat="server" AllowPaging="True" onrowdatabound="GridView1_RowDataBound"
 onpageindexchanging="GridView1_PageIndexChanging" PageSize="9"
 CssClass="GridStyle" >
		 <HeaderStyle BackColor="#CCCCCC" />
		 <PagerStyle Font-Bold="True" Font-Size="Medium" Height="25px" />
	 </asp:GridView>

No row databound verifico cada campo addicionado, tirando de coluna "Nome", e ver a extensao para addicionar a imagem.

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
 {
	 if (e.Row.RowType == DataControlRowType.DataRow)
	 {
		 string[] str = e.Row.Cells[1].Text.Split('.');
		 switch (str[1])
		 {
			 case "jpg":
				 e.Row.Cells[5].Text = "<asp:ImageButton runat='server' ImageUrl='~/IMGicon/icon_imagem.jpg' onclick='ImageButton1_Click' />";
				 break;
			 case "docx":
				 e.Row.Cells[5].Text = "<asp:ImageButton runat='server' ImageUrl='~/IMGicon/icon_word.jpg' onclick='ImageButton1_Click' />";
				 break;
			 default:
				 e.Row.Cells[5].Text = "<asp:ImageButton runat='server' ImageUrl='~/IMGicon/icon_docgeral.jpg' onclick='ImageButton1_Click' />";
				 break;

		 }
	 }
 }

Acham que é método apropriado ou não?

e ja agora se for, tentam me dizer o porque nao me aparecem as imagens. Porque eu ja os tive visiveis mas dps de addicionar onclick, desapereceram...

deste já agradeço

Cumps

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.   Restore formatting

  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.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.