Image from dataset in ASP gridview - asp.net

I receive a certain image name in a boundfield (i have two images in the same folder) and it comes from testing in the codebehind and binding a datatable into this gridview.
example:
it comes as "image1.jpg" or "image2.jpg"
I'd like this text not to be displayed, instead, i want these images that are in
/folder1/folder2 of my solution (i access images like this, and it works)
either i transform it into html tag...
<img src='/folder1/folder2/image1.jpg' border='0'>
(that's the reason for the first question i've made)
...OR I create an asp image somehow inside the boundfield.
Is there any way to do so ?

I've used:
<asp:Literal runat="server" Text="<%#Eval("myField")%>" />
Inside a templatefield

Related

Colorbox and ASP.NET in a bound Datalist

My images are stored in a SQL database. I bind to the table and use the generated image control and a ashx handler. No problem. I now have the thumbnail image surrounded by a anchor tag. The problem come in finding the large image thats in a hidden div and display ONLY that.. I don't want a gallery just that one image. If you are reading this you know that datalists when generating their controls assigns mangled ID's to their components. How can I address that image from my thumbnail image?
<asp:DataList ID="datalist" runat="server" RepeatColumns="3" RepeatDirection="Horizontal">
<ItemTemplate>
<a class="colorme" href="#">Actual thumbnail image</a>
<div style="display:none">
<div id="colorme" runat="server">Actual image to display
</div>
</div>
</ItemTemplate>
</asp:DataList>
ASP.NET 4.0 no master page.
Assign ID and run at server for your Image and use
<%= yourimage.ClientID %> this will return that particular image wherever you'll use it..not the mangled IDs generated by Datalist control.
The simplest solution would be to use jQuery, and find the element using the next-sibling selector.
$(".colorme").click(function(){
$(this).find("~ div").show();
});
This would work no matter how many images you have on the page.

ASP.NET: checkboxlist with textbox?

I'm working in ASP.NET and I have a CheckBoxList where I want one of the options to be basically like "Other: _." So I need to include a textbox where the user can fill in their own option. It doesn't seem like there's a way to include a textbox inside of a checkboxlist, however. What's the best way to make this work?
-UPDATE-
If using a separate textbox control, how do I position it so it will align correctly with the checkbox?
Make the textbox a separate control on the page, then in your codebehind, check to see if other is checked. If it is, pull the value of the textbox, and use that.
To answer the question in your edit: You'll have to play with the CSS of the page to get it positioned correctly. How you do it depends on the layout of the page, among other things. I recommend posting some of the HTML from your page in another question and ask about how to position them.
What #Kyle Trauberman said...
Make the textbox a separate control on
the page, then in your codebehind,
check to see if other is checked. If
it is, pull the value of the textbox,
and use that.
Plus use javascript to hide or gray out the option unless the checkbox is selected.
string test="";
<asp:CheckBoxList ID="chk_list" runat="server">
<asp:ListItem Value="00">xxxx</asp:ListItem>
</asp:CheckBoxList>
<asp:TextBox ID="other" runat="server"></asp:TextBox>
inside the for loop
if (chk_list.Items[i].Value == "00")
{
test +=chk_list.Items[i].Text + other.Text;
}

Databound DIV in asp .net

Looking for a custom ASP .NET control were the InnerHTML of a DIV is connected to a databas to fetch the content to render the HTML content from the databas inside the DIV.
Is there one out there I have missed or anyone could tell if its possible to make my own DIV component to make it DataBound?
Thanks,
Stefan
You can't databind to a div, but you can databind to something like a Repeater, which is mainly good for showing rows of data (i.e. repeating the same markup for multiple data items).
If you just want to show one field from one row, you're probably better off with something like a literal:
<div>
<asp:Literal id="myLiteral" runat="server" />
</div>
And then in the code behind...
myLiteral.Text = "some string from the database or wherever";

CheckboxList - Use web.config value in text field

The scenario I'm dealing with is I have a set of entries in a database that have an image associated with them. This image needs to be 'accepted' or 'rejected' via a web interface.
I'm using ASP.NET WebForms.
I'm attempting to databind my recordset of entires to a CheckBoxList control. I would like to combine data from my dataset with information from the web.config file and plain text to display an image:
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
DataSourceID="DataSource1"
DataTextField="ImageIdentifier"
DataValueField="EntryId"
DataTextFormatString="<img src='<%$ AppSettings:GetImageUrl %>{0}' />" />
This approach correctly outputs the plain text and the DataTextField value, however it does not interpret the code inside the <% %> block and prints the whole thing literally in the generated HTML, in spite of it being correctly highlighted in the editor.
Is this possible to achieve declaratively? If not, is there a better way than iterating through the entries in the list in code on the OnDataBound event?
Thanks in advance,
Jamie
I believe you're using the wrong <% tag. In order to evaluate in a binding expression like that it should be <%#
What does your web.config look like? You'll won't be able to use that binding syntax here - you'll have to hook into the databound event of the checkbox and iterate each checkbox, updating them as necessary from the values in your web.config.
EDIT
If you don't want to iterate each checkbox after the checkboxlist has been databound, you'll have to update your dataset first, before you bind to it.

ASP .NET: Page breaking when using multiple gridview in aspx page for printing

Here is the issue:
We have a report with many gridviews in an aspx page. However, when we print them, they don't page correctly, as one would expect.
I found a library that will create page breaks correctly within a single page break. But, yet again, it is not aware about other gridviews, so if the last gridview ended in the middle of the page, the first page for the next gridview will be broken.
How can we print these multiple gridviews with proper print paging?
The library that I found:
http://www.codeproject.com/KB/custom-controls/GridViewPrinting.aspx
If you want each GridView to print on a new page, you could wrap each GridView in a div and set the "page-break-after" css property to "always" for each div. So, it might look like:
<div style="page-break-after:always;">
<asp:GridView ID="GridView1" runat="server">
...
</asp:GridView>
</div>
Omit the "page-break-after" property on the last GridView so you don't print an extra page.

Resources