Showing posts with label html. Show all posts
Showing posts with label html. Show all posts

Saturday, March 24, 2012

populate standard HTML controls

I have a standard HTML control:
<SELECT id="leftBox" size="50">
</SELECT>
and I want to populate this with Options from the db:
<OPTION value="1234">John Smith</OPTION>
How can I do this?
NOTE: I need to be able to manipulate this box via a javascript I havethat works with standard HTML select controls. So I can't use anASP:ListBox.
Any suggestions?
Thanks.

asp:dropdownlist will render as a select ...

An ASP:ListBox gets rendered to the client as a <SELECT>... so you can use the javascript that you have with it.
Are you positive? This javascript I have I've been using for a longtime (pre-ASP.NET), and it works great. When I try to use it withASP:ListBox, I get javascript errors stating that "option" is not avalid something or other of that control.

You can use listbox if you have multiple items selected. If you are only going to have 1 item selected, opt for the dropdownlist.If you are still having problems, post some code so we can help you.

Nick

Wednesday, March 21, 2012

Populating a control with HTML file contents, images included?

publicvoid LoadToLabel()
{
using (StreamReader rdr =newStreamReader(FileUpload1.PostedFile.FileName))
{
string uploadedHTML = rdr.ReadToEnd();
textLabel.Text = uploadedHTML.ToString();
}
}

So far I have that, but the problem is that if the HTML file has an image displayed in it, the image doesn't show up because it's just copying the text. How would I be able to transfer the entire HTML page to a control? Like a panel or something like that, is it possible? And have the images come with it?

You should use LiteralControl for this purpose.


So if I switch it to a literal would it display the images as well?


I just switched it to a literal control and it still ignores the images. What must I do?


Yup. The LiteralControl will display the HTML exactly as you create it. See it as a place holder for output you create from code behind. Good luck!


OK, let me get this straight. You upload a HTML document containing <img> tags, which you then want to print out in the page, right?

If you do a view source in the resulting page, how does it look?

If the image urls in the uploaded page are relative then that is maybe what's causing the problem. Please give an example of how this tag looks like.

Also, if you upload a complete HTML document (with head/body) then you will render a page that is not valid (containing duplicate elements).


What does image urls being relative mean? Like pointing to a specific spot and not "~/Images/image.gif" etc.?

I did a view source on the page that uploads and displays the HTML document and yes you're right, there are now duplicate elements. It uploads everything within the uploaded documents <HTML></HTML> tags. How do I go about just grabbing what's in the body, and not the body tags themselves as that would be a duplicate element as well?


A relative path is one that does not begin with a / or http://something, example:

<img src="http://pics.10026.com/?src=images/ticker.gif">

A relative path is always calculated from the place where it is accessed.

If your (uploaded) page contains relative image paths, then to display these images correctly, you need to either rebuild the path (by parsing), or copy the contents of the path into the same folder as your upload page (not a viable solution).

Or you could make sure the user uploads all the images as well.

In either way, you have some parsing to do in order to get the uploaded file to display correctly. Also you must parse the file to get the actual contents of the file, and get past <html><body> and so on.

One option you have is to show the uploaded file in an iframe which would allow you to show the document as-is (although images would still require parsing).


How would I go about parsing the uploaded file so it displays properly with the images included within the literal control?


Strange... I could almost see that question comingWink Well, parsing text is not trivial, and I am not able to give you the code as it would take some time to develop and test. But here's how I would do: Define a regexp, that finds <img tags, and then replaces the src value with your "path prefixed" value.

Problem is that these tags can come in so many flavours, it's almost impossible to guarantee that the parser matches them correctly. Parsing HTML is kind of re-inventing the wheel again (the wheel being the browser ;-)

Uhm, I'm sorry, can't help you any further with this. But if you google a little on Regular expressions and spend some time trialing and erroring then you might reach your goal. Good luck!


Thank you so much for your help!

populating a Drop down list

hello,

I need to populate a drop down list when the user clicks
on the arrow button.

how do i do this.

Should i use a html select control or is it possible
using the asp:dropdownlistBoth are ok.

for saving program code, you can choose DropDownList,

if your data come from db, two lines will give your the result
ddl.DataSource = yourProcedure;
ddl.DataBind();

> hello,
> I need to populate a drop down list when the user clicks
> on the arrow button.
> how do i do this.
> Should i use a html select control or is it possible
> using the asp:dropdownlist

What i mean is that the list should only be populated
when the user clicks on it.

Until then it should be empty

>--Original Message--
>Both are ok.
>for saving program code, you can choose DropDownList,
> if your data come from db, two lines will give your the
result
> ddl.DataSource = yourProcedure;
> ddl.DataBind();
>> hello,
>>
>> I need to populate a drop down list when the user
clicks
>> on the arrow button.
>>
>> how do i do this.
>>
>> Should i use a html select control or is it possible
>> using the asp:dropdownlist
>>
>>
>
>.
Can you supply your reasoning for this requirement? This is not the
normal usage of this type of control. You can certainly populate the
list based on selections from other controls, but it might be
difficult to do using the onclick event of the listbox itself.

On Mon, 5 Jul 2004 07:28:15 -0700, "Casey"
<anonymous@.discussions.microsoft.com> wrote:

>
>What i mean is that the list should only be populated
>when the user clicks on it.
>Until then it should be empty
>
>
>>--Original Message--
>>Both are ok.
>>
>>for saving program code, you can choose DropDownList,
>>
>> if your data come from db, two lines will give your the
>result
>> ddl.DataSource = yourProcedure;
>> ddl.DataBind();
>>
>>> hello,
>>>
>>> I need to populate a drop down list when the user
>clicks
>>> on the arrow button.
>>>
>>> how do i do this.
>>>
>>> Should i use a html select control or is it possible
>>> using the asp:dropdownlist
>>>
>>>
>>
>>
>>.
>
Dan,

I am connecting to server at a distant location to
retrieve the data for the listbox, and the data has to be
loaded up only when the user wants to look at the
information,

I know there are other ways of doing this but this is
requested by the user

can you give me any ideas on this..

>--Original Message--
>Can you supply your reasoning for this requirement? This
is not the
>normal usage of this type of control. You can certainly
populate the
>list based on selections from other controls, but it
might be
>difficult to do using the onclick event of the listbox
itself.
>
>On Mon, 5 Jul 2004 07:28:15 -0700, "Casey"
><anonymous@.discussions.microsoft.com> wrote:
>>
>>
>>What i mean is that the list should only be populated
>>when the user clicks on it.
>>
>>Until then it should be empty
>>
>>
>>
>>
>>>--Original Message--
>>>Both are ok.
>>>
>>>for saving program code, you can choose DropDownList,
>>>
>>> if your data come from db, two lines will give your
the
>>result
>>> ddl.DataSource = yourProcedure;
>>> ddl.DataBind();
>>>
>>>> hello,
>>>>
>>>> I need to populate a drop down list when the user
>>clicks
>>>> on the arrow button.
>>>>
>>>> how do i do this.
>>>>
>>>> Should i use a html select control or is it possible
>>>> using the asp:dropdownlist
>>>>
>>>>
>>>
>>>
>>>.
>>>
>.
There is a user event that occurs when you click on the dropdown list
I think (not 100% sure). You may be able to link to that. However...

If you are going to go to the server to get the data, this will be a
significant pause to build the list. Also, when you come back, you
would have to manually "open" that list as if you just clicked on it.
Not exactly a smooth transition.

I suggest that you should be able to determine when the list would
need to be built and do this when necessary. Worst case, provide a
button that says "Load List" that the user can click and then populate
the dropdown list.

On Mon, 5 Jul 2004 14:19:26 -0700, "Casey"
<anonymous@.discussions.microsoft.com> wrote:

>Dan,
> I am connecting to server at a distant location to
>retrieve the data for the listbox, and the data has to be
>loaded up only when the user wants to look at the
>information,
>I know there are other ways of doing this but this is
>requested by the user
>can you give me any ideas on this..
>
>>--Original Message--
>>Can you supply your reasoning for this requirement? This
>is not the
>>normal usage of this type of control. You can certainly
>populate the
>>list based on selections from other controls, but it
>might be
>>difficult to do using the onclick event of the listbox
>itself.
>>
>>
>>On Mon, 5 Jul 2004 07:28:15 -0700, "Casey"
>><anonymous@.discussions.microsoft.com> wrote:
>>
>>>
>>>
>>>What i mean is that the list should only be populated
>>>when the user clicks on it.
>>>
>>>Until then it should be empty
>>>
>>>
>>>
>>>
>>>>--Original Message--
>>>>Both are ok.
>>>>
>>>>for saving program code, you can choose DropDownList,
>>>>
>>>> if your data come from db, two lines will give your
>the
>>>result
>>>> ddl.DataSource = yourProcedure;
>>>> ddl.DataBind();
>>>>
>>>>> hello,
>>>>>
>>>>> I need to populate a drop down list when the user
>>>clicks
>>>>> on the arrow button.
>>>>>
>>>>> how do i do this.
>>>>>
>>>>> Should i use a html select control or is it possible
>>>>> using the asp:dropdownlist
>>>>>
>>>>>
>>>>
>>>>
>>>>.
>>>>
>>
>>.
>
thanks for your help dan..

I will take your advice,

regards

casey

>--Original Message--
>There is a user event that occurs when you click on the
dropdown list
>I think (not 100% sure). You may be able to link to
that. However...
>If you are going to go to the server to get the data,
this will be a
>significant pause to build the list. Also, when you come
back, you
>would have to manually "open" that list as if you just
clicked on it.
>Not exactly a smooth transition.
>I suggest that you should be able to determine when the
list would
>need to be built and do this when necessary. Worst case,
provide a
>button that says "Load List" that the user can click and
then populate
>the dropdown list.
>
>On Mon, 5 Jul 2004 14:19:26 -0700, "Casey"
><anonymous@.discussions.microsoft.com> wrote:
>>Dan,
>>
>> I am connecting to server at a distant location to
>>retrieve the data for the listbox, and the data has to
be
>>loaded up only when the user wants to look at the
>>information,
>>
>>I know there are other ways of doing this but this is
>>requested by the user
>>
>>can you give me any ideas on this..
>>
>>
>>
>>>--Original Message--
>>>Can you supply your reasoning for this requirement?
This
>>is not the
>>>normal usage of this type of control. You can
certainly
>>populate the
>>>list based on selections from other controls, but it
>>might be
>>>difficult to do using the onclick event of the listbox
>>itself.
>>>
>>>
>>>On Mon, 5 Jul 2004 07:28:15 -0700, "Casey"
>>><anonymous@.discussions.microsoft.com> wrote:
>>>
>>>>
>>>>
>>>>What i mean is that the list should only be populated
>>>>when the user clicks on it.
>>>>
>>>>Until then it should be empty
>>>>
>>>>
>>>>
>>>>
>>>>>--Original Message--
>>>>>Both are ok.
>>>>>
>>>>>for saving program code, you can choose DropDownList,
>>>>>
>>>>> if your data come from db, two lines will give your
>>the
>>>>result
>>>>> ddl.DataSource = yourProcedure;
>>>>> ddl.DataBind();
>>>>>
>>>>>> hello,
>>>>>>
>>>>>> I need to populate a drop down list when the user
>>>>clicks
>>>>>> on the arrow button.
>>>>>>
>>>>>> how do i do this.
>>>>>>
>>>>>> Should i use a html select control or is it
possible
>>>>>> using the asp:dropdownlist
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>.
>>>>>
>>>
>>>.
>>>
>.

populating a Drop down list

hello,
I need to populate a drop down list when the user clicks
on the arrow button.
how do i do this.
Should i use a html select control or is it possible
using the asp:dropdownlistBoth are ok.
for saving program code, you can choose DropDownList,
if your data come from db, two lines will give your the result
ddl.DataSource = yourProcedure;
ddl.DataBind();

> hello,
> I need to populate a drop down list when the user clicks
> on the arrow button.
> how do i do this.
> Should i use a html select control or is it possible
> using the asp:dropdownlist
>

What i mean is that the list should only be populated
when the user clicks on it.
Until then it should be empty

>--Original Message--
>Both are ok.
>for saving program code, you can choose DropDownList,
> if your data come from db, two lines will give your the
result
> ddl.DataSource = yourProcedure;
> ddl.DataBind();
>
clicks
>
>.
>
Can you supply your reasoning for this requirement? This is not the
normal usage of this type of control. You can certainly populate the
list based on selections from other controls, but it might be
difficult to do using the onclick event of the listbox itself.
On Mon, 5 Jul 2004 07:28:15 -0700, "Casey"
<anonymous@.discussions.microsoft.com> wrote:
>
>What i mean is that the list should only be populated
>when the user clicks on it.
>Until then it should be empty
>
>
>result
>clicks
Dan,
I am connecting to server at a distant location to
retrieve the data for the listbox, and the data has to be
loaded up only when the user wants to look at the
information,
I know there are other ways of doing this but this is
requested by the user
can you give me any ideas on this..

>--Original Message--
>Can you supply your reasoning for this requirement? This
is not the
>normal usage of this type of control. You can certainly
populate the
>list based on selections from other controls, but it
might be
>difficult to do using the onclick event of the listbox
itself.
>
>On Mon, 5 Jul 2004 07:28:15 -0700, "Casey"
><anonymous@.discussions.microsoft.com> wrote:
>
the
>.
>
There is a user event that occurs when you click on the dropdown list
I think (not 100% sure). You may be able to link to that. However...
If you are going to go to the server to get the data, this will be a
significant pause to build the list. Also, when you come back, you
would have to manually "open" that list as if you just clicked on it.
Not exactly a smooth transition.
I suggest that you should be able to determine when the list would
need to be built and do this when necessary. Worst case, provide a
button that says "Load List" that the user can click and then populate
the dropdown list.
On Mon, 5 Jul 2004 14:19:26 -0700, "Casey"
<anonymous@.discussions.microsoft.com> wrote:
>Dan,
> I am connecting to server at a distant location to
>retrieve the data for the listbox, and the data has to be
>loaded up only when the user wants to look at the
>information,
>I know there are other ways of doing this but this is
>requested by the user
>can you give me any ideas on this..
>
>
>is not the
>populate the
>might be
>itself.
>the
thanks for your help dan..
I will take your advice,
regards
casey

>--Original Message--
>There is a user event that occurs when you click on the
dropdown list
>I think (not 100% sure). You may be able to link to
that. However...
>If you are going to go to the server to get the data,
this will be a
>significant pause to build the list. Also, when you come
back, you
>would have to manually "open" that list as if you just
clicked on it.
>Not exactly a smooth transition.
>I suggest that you should be able to determine when the
list would
>need to be built and do this when necessary. Worst case,
provide a
>button that says "Load List" that the user can click and
then populate
>the dropdown list.
>
>On Mon, 5 Jul 2004 14:19:26 -0700, "Casey"
><anonymous@.discussions.microsoft.com> wrote:
>
be
This
certainly
possible
>.
>

Friday, March 16, 2012

Populating a html table

How to populate a html table using data from sql database..

The simplest answer is the use a gridview to display a dataset selected from the database.