Showing posts with label text. Show all posts
Showing posts with label text. Show all posts

Thursday, March 29, 2012

pop up windows with img and text from...?

using vb.net, with sql 2000 personal edition.

I'm trying to create a portfolio page, the pages would be divided into years from 2001 ~ 2004 with each page a link of projects that my company has done. when the link is clicked it would open a new window with both image and text.

my question is how should i build this pop up page, with over 90 images i do not want to create individual aspx pop up windows, so if i was to get img and text info where should it be coming from? would sql server or is there was a to put this info in the project page? I haven't a clue, plz help.

ps. if you can point me to an example on the net that would be great..

focusA good place to start may be the following tutorial:
A Robust Image Gallery for ASP.NET
wow thanks NewKid2~

i'm still reading it but its a great example, not only for my project but for my personal use as well, also i love the fact that its in vb.net there should be a page called top 10 everyday examples in vb.net for the noobie in you!

focus
> there should be a page called top 10 everyday examples in vb.net

Well, the same guys have written a bunch of ASP.NET articles, most of them using VB.NET, and all written in an easy-to-understand way.

You can see the entire list of their articles here:
http://aspnet.4guysfromrolla.com

Poplulating Text Field with DropDown selection

Hi folks. Here's a simple question. Trying to populate some text fields based on a dropdown menu selection, but it doesn't work. When a selection is made in the dropdown menu, it seems to default to the selectedValue =2. Not sure why. Any advice would be much appreciated. Thanks! Here's the code:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { TextBox1.Text =""; TextBox2.Text =""; TextBox3.Text ="";if (DropDownList1.SelectedValue =="0") TextBox1.Text ="blah";if (DropDownList1.SelectedValue =="1") TextBox1.Text ="blahblah";if (DropDownList1.SelectedValue =="2") TextBox1.Text ="blahblahblah"; }

Are you dynamicalluy populating the dropdown list in your code behind? If you are, the Page_OnLoad event is running which is populating your dropdownlist on every postback. To make sure this doesnt happen, you should populate when teh page is not posted back. in other words...

if(!Page.IsPostback){// populate my dropdownlist}

If you are not dynamically populating the dropdownlist, please make sure your viewstate is turned on, that way the server knows that index to preserve when the page is loaded again.

EnableViewState="true"

Hope this helps.


If you are adding the items to the dropdown through code in Page_Load then check if they are inside If (!Ispostback) block.


hi..

i think u can have a break point in the page load or start of selected index changed event..

and find the value..

if not..

check in the design view that item 2 isSelected=true..

correct me if i'm wrong..


Thanks to all for the suggestions. The dropDownList was statically populated from the control properties in the ASPX page. I tinkered with this for a long while, but could NOT get it to work. So, I changed approach and populated the list by making an array in the code, and now it works as designed. Thanks again. Here is the code, in case anybody is interested.

protected void Page_Load(object sender, EventArgs e) {if (!IsPostBack) {// 2 dimensional array for dropDown liststring[,] forms = { {"blah","0"}, {"blah blah","1"}, {"blah blah blah","2"} };// populate listfor (int i = 0; i < forms.GetLength(0); i++) {//add both text and value DropDownList1.Items.Add(new ListItem(forms[i, 0], forms[i, 1])); } } }protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) {if (DropDownList1.SelectedIndex != -1) { TextBox1.Text = DropDownList1.SelectedItem.Text; } }

FYI... regarding the orginal post, the reason the textBox wasn't populated correctly was a simple syntax error. Used cascading IF statement without ELSE IF or switch statement.

Popping opening a mail client and pass a subject parameter...

Hi:

Is there a way to pop open a mail client and pass in a text string for the
subject and possibly other parts of a standard mail message? The "mailto:"
attribute of hyplerlink leaves these blank.

Thanks,
Charlieread up on the mailto: link, it does have a &Subject='text'&Body='text'
attribute IIRC

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com

"Charlie@.CBFC" <charle1@.comcast.net> wrote in message
news:eSlBhiR4DHA.1752@.tk2msftngp13.phx.gbl...
> Hi:
> Is there a way to pop open a mail client and pass in a text string for the
> subject and possibly other parts of a standard mail message? The
"mailto:"
> attribute of hyplerlink leaves these blank.
> Thanks,
> Charlie

Monday, March 26, 2012

Populate a DropDownList

I need to populate a dropdownlist with items form one SQL Table in SqlDataSource1 but the selected value and the data text need to match the ones that are already into another SQL Table in SqlDataSource2.

Any Sugestions?

You can manually compare the data between the tables in codebehind using the classes found in System.Data.SqlClient & System.Data.Sql. Then you can use the DropDownList.Items.Add(new ListItem()) methods to add new items to your dropdownlist.

Populate a label with text from a drop down list box

I know this is probably real easy but I can't figure it out.
I'm trying to grab the text that appears in a drop down list server control
and place it in a label server control on the same page. I can get the
selected value, that's easy. But I want the text.
Thanksddl.SelectedItem.Text
Eliyahu
"Mardy" <Mardy@.discussions.microsoft.com> wrote in message
news:983E0BF1-2741-4B22-920F-6F7708CA712B@.microsoft.com...
> I know this is probably real easy but I can't figure it out.
> I'm trying to grab the text that appears in a drop down list server
control
> and place it in a label server control on the same page. I can get the
> selected value, that's easy. But I want the text.
> Thanks
>

Populate a label with text from a drop down list box

I know this is probably real easy but I can't figure it out.

I'm trying to grab the text that appears in a drop down list server control
and place it in a label server control on the same page. I can get the
selected value, that's easy. But I want the text.

Thanksddl.SelectedItem.Text

Eliyahu

"Mardy" <Mardy@.discussions.microsoft.com> wrote in message
news:983E0BF1-2741-4B22-920F-6F7708CA712B@.microsoft.com...
> I know this is probably real easy but I can't figure it out.
> I'm trying to grab the text that appears in a drop down list server
control
> and place it in a label server control on the same page. I can get the
> selected value, that's easy. But I want the text.
> Thanks

Populate a ListBox based on database search

I am trying to populate a ListBox with values retrieved from a database based on a search. I have a TextBox in which the user will enter the text they wish to search for, a Button which will submit the text, and then a ListBox which is invisible until values are returned from the database. I have a SqlDataSource with a SelectCommand saying "SELECT * FROM [table] WHERE [name] LIKE '@dotnet.itags.org.Parameter'". I want to know how to bind the value in the TextBox to the "@dotnet.itags.org.Parameter" in the Sql statement. I am quite new at programming, and I'm sure this is quite a simple task. Any help would be appreciated.

MYSQL:

myCommand.Parameters.Clear();
myCommand.CommandText = "SELECT * FROM [table] WHERE [name] LIKE (?)";
myCommand.Parameters.Add(new OdbcParameter(null, txtSearch.Text));

MSSQL:

myCommand.Parameters.Clear();
myCommand.CommandText = "SELECT * FROM [table] WHERE [name] LIKE @.search";
myCommand.Parameters.Add(new SqlParameter("@.search", txtSearch.Text));


Thanks for the reply. Where would I put this code? I'm using MSSql, but I am not using any stored procedures. All my SQL code is on my .aspx page. Should this go somewhere on my .aspx page or in my VB codebehind?

This would go in your code behind, in the onclick method from your button (double click your submit button and you'll go automatically to your onclick method).

Remember the code I gave in the example is C# code, I don't know the correct syntax in VB.net but it should get you started.


This should help:

http://www.asp.net/learn/dataaccess/default.aspx?tabid=63

Cheers

Populate asp:label with text from db and retain formatting?

set the text box Text Mode property to MultiLine.

Av.

"Tony" <anonymous@dotnet.itags.org.discussions.microsoft.com> wrote in message
news:7B9C3796-02D8-4180-AD93-8572746CD951@dotnet.itags.org.microsoft.com...
> Hello,
> Im can't seem to figure this out OR find any documentation on if it's
> possible; I need to populate the value of an asp:label with text retrieved
> from the database. However when the text is populated I need to retain
> carriage returns and indents that the text contains. That way if I want to
> see this:
> Some text with a manual
> carriage return.
> 1. this is one.
> 2. this is two.
> It doesn't look like this:
> Some text with a manual carriage return. 1. this is one. 2. this is two.
> I've tried enclosing the text in <pre></pre> tags before the text is
> assigned to the label and it works fine except for 2 things. The text is
> rendered in a non-styled font and in the instance that the user entered
> really long text and didn't manullay hit a carriage return- which causes
> the text continue to the right instead of automatically wrapping even
> though I define a width on my label, the cell the label is within, etc..
> Does anyone know how to get this to work? I must have looked around on the
> net for hours!TextMode is not a property for a label but a textbox. I have tried using a textbox control with this property set to multiline previously however without specifically setting the height of the textbox I end up with vertical scrollbars- which I cannot have because this is for a printable report.

Populate asp:label with text from db and retain formatting?

Hello,
Im can't seem to figure this out OR find any documentation on if it's possib
le; I need to populate the value of an asp:label with text retrieved from th
e database. However when the text is populated I need to retain carriage ret
urns and indents that the t
ext contains. That way if I want to see this:
Some text with a manual
carriage return.
1. this is one.
2. this is two.
It doesn't look like this:
Some text with a manual carriage return. 1. this is one. 2. this is two.
I've tried enclosing the text in <pre></pre> tags before the text is assigne
d to the label and it works fine except for 2 things. The text is rendered i
n a non-styled font and in the instance that the user entered really long te
xt and didn't manullay hit
a carriage return- which causes the text continue to the right instead of au
tomatically wrapping even though I define a width on my label, the cell the
label is within, etc..
Does anyone know how to get this to work? I must have looked around on the n
et for hours!set the text box Text Mode property to MultiLine.
Av.
"Tony" <anonymous@.discussions.microsoft.com> wrote in message
news:7B9C3796-02D8-4180-AD93-8572746CD951@.microsoft.com...
> Hello,
> Im can't seem to figure this out OR find any documentation on if it's
> possible; I need to populate the value of an asp:label with text retrieved
> from the database. However when the text is populated I need to retain
> carriage returns and indents that the text contains. That way if I want to
> see this:
> Some text with a manual
> carriage return.
> 1. this is one.
> 2. this is two.
> It doesn't look like this:
> Some text with a manual carriage return. 1. this is one. 2. this is two.
> I've tried enclosing the text in <pre></pre> tags before the text is
> assigned to the label and it works fine except for 2 things. The text is
> rendered in a non-styled font and in the instance that the user entered
> really long text and didn't manullay hit a carriage return- which causes
> the text continue to the right instead of automatically wrapping even
> though I define a width on my label, the cell the label is within, etc..
> Does anyone know how to get this to work? I must have looked around on the
> net for hours!
>
TextMode is not a property for a label but a textbox. I have tried using a t
extbox control with this property set to multiline previously however withou
t specifically setting the height of the textbox I end up with vertical scro
llbars- which I cannot have
because this is for a printable report.
Hi, Tony
You might write a function to conver the strin, like:
'Get str from database
str = "Some text with a manual carriage return." & vbCr & vbTab & "1. this i
s one. " & vbNewLine & vbTab & "2. this is two."
str = Replace(str, " ", " ")
str = Replace(str, vbTab, " ") 'De
pend how many spaces do you want for a tab.
str = Replace(str, vbNewLine, "<br/>")
str = Replace(str, vbCr, "<br/>")
str = Replace(str, vbLf, "<br/>")
Label1.Text = str
Hope this helps,
Bin Song, MCP
even better ..use a StringBuilder :)
Swanand Mokashi
Microsoft Certified Solution Developer (.NET)
Microsoft Certified Application Developer (.NET)
http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
"Bin Song, MCP" <anonymous@.discussions.microsoft.com> wrote in message
news:E9930659-B6E5-47F0-A42E-88BE5B97B7A9@.microsoft.com...
> Hi, Tony
> You might write a function to conver the strin, like:
> 'Get str from database
> str = "Some text with a manual carriage return." & vbCr & vbTab &
"1. this is one. " & vbNewLine & vbTab & "2. this is two."
> str = Replace(str, " ", " ")
> str = Replace(str, vbTab, " ") '
Depend
how many spaces do you want for a tab.
> str = Replace(str, vbNewLine, "<br/>")
> str = Replace(str, vbCr, "<br/>")
> str = Replace(str, vbLf, "<br/>")
> Label1.Text = str
> Hope this helps,
> Bin Song, MCP
>
The problem is that there is no universally accepted definition of how
preformatted ascii text should be rendered on the web. You just have
to munge it yourself. In the case you gave I would suggest something
like:
outputLabel.Text = dbText.Replace(@."\n", "<BR>").Replace(@."\t",
@." ");
There is no "easy way out" that I'm aware of.
Hope that helps
Ian
"Tony" <anonymous@.discussions.microsoft.com> wrote in message news:<7B9C3796-02D8-4180-AD93
-8572746CD951@.microsoft.com>...
> Hello,
> Im can't seem to figure this out OR find any documentation on if it's possible; I
need to populate the value of an asp:label with text retrieved from the database. Ho
wever when the text is populated I need to retain carriage returns and indents that
the
text contains. That way if I want to see this:
> Some text with a manual
> carriage return.
> 1. this is one.
> 2. this is two.
> It doesn't look like this:
> Some text with a manual carriage return. 1. this is one. 2. this is two.
> I've tried enclosing the text in <pre></pre> tags before the text is
assigned to the label and it works fine except for 2 things. The text
is rendered in a non-styled font and in the instance that the user
entered really long text and didn't manullay hit a carriage return-
which causes the text continue to the right instead of automatically
wrapping even though I define a width on my label, the cell the label
is within, etc..
> Does anyone know how to get this to work? I must have looked around on the net for
hours!
AWESOME!! Thanks Ian!! All I had to do is lose the '@.' sign (not sure if it'
s because I use C#) and it works. I cannot tell you how freakin ecstatic I a
m that your solution worked. Thank you!

populate checkboxlist from XmlDataSource (ASP.net 2.0)

can somebody please show me some code that will let me populate a
checkboxlist from the xmldatasource, and have the text property set to the
names in the xml file
thanks
you can also email me at i_am_the_freshmaka@dotnet.itags.org.hotmail.commike <mike@.discussions.microsoft.com> ha scritto:
> can somebody please show me some code that will let me populate a
> checkboxlist from the xmldatasource, and have the text property set
> to the names in the xml file
> thanks
With this XML file:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<item value="1" text="Value 1" />
<item value="2" text="Value 2" />
<item value="3" text="Value 3" />
</root>
And this code:
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
DataSourceID="XmlDataSource1"
DataTextField="text" DataValueField="value">
</asp:CheckBoxList><asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="~/Data/XMLFile.xml"></asp:XmlDataSource>
AZ [Microsoft - .NET MVP]
Mia Home page: http://ciclismo.sitiasp.it
Asp.Net community: http://www.aspitalia.com
Il mio blog: http://blogs.aspitalia.com/az
<Lookup>
<Lookup_Entry>
<Ts>
<T>
<M>context</M>
<V>type</V>
<Va>Citizen</Va>
</T>
</Ts>
<U>.html</U>
</Lookup_Entry>
</Lookup>
example of xml file is above
code:
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/Lookup
table.xml"
XPath='/Lookup/Lookup_Entry/Ts/T/Va[../../T[M = "context" and V
= "type"]]'>
</asp:XmlDataSource>
<asp:CheckBoxList
ID="CheckBoxList1"
runat="server"
DataSourceID="XmlDataSource1">
</asp:CheckBoxList>
Now how do i get each <Va> that is returned with the xmldatasource as a item
in my checkboxlist
displayed now when run is with a checkbox to the left of each item:
System.Web.UI.WebControls.XmlDataSourceNodeDescriptor
System.Web.UI.WebControls.XmlDataSourceNodeDescriptor
System.Web.UI.WebControls.XmlDataSourceNodeDescriptor
System.Web.UI.WebControls.XmlDataSourceNodeDescriptor
System.Web.UI.WebControls.XmlDataSourceNodeDescriptor
System.Web.UI.WebControls.XmlDataSourceNodeDescriptor
System.Web.UI.WebControls.XmlDataSourceNodeDescriptor
mike
"Andrea Zani" wrote:

> mike <mike@.discussions.microsoft.com> ha scritto:
> With this XML file:
> <?xml version="1.0" encoding="utf-8" ?>
> <root>
> <item value="1" text="Value 1" />
> <item value="2" text="Value 2" />
> <item value="3" text="Value 3" />
> </root>
> And this code:
> <asp:CheckBoxList ID="CheckBoxList1" runat="server"
> DataSourceID="XmlDataSource1"
> DataTextField="text" DataValueField="value">
> </asp:CheckBoxList><asp:XmlDataSource ID="XmlDataSource1" runat="server"
> DataFile="~/Data/XMLFile.xml"></asp:XmlDataSource>
> --
> AZ [Microsoft - .NET MVP]
> Mia Home page: http://ciclismo.sitiasp.it
> Asp.Net community: http://www.aspitalia.com
> Il mio blog: http://blogs.aspitalia.com/az
>
>

populate checkboxlist from XmlDataSource (ASP.net 2.0)

can somebody please show me some code that will let me populate a
checkboxlist from the xmldatasource, and have the text property set to the
names in the xml file

thanks
you can also email me at i_am_the_freshmaka@dotnet.itags.org.hotmail.commike <mike@.discussions.microsoft.com> ha scritto:
> can somebody please show me some code that will let me populate a
> checkboxlist from the xmldatasource, and have the text property set
> to the names in the xml file
> thanks

With this XML file:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<item value="1" text="Value 1" />
<item value="2" text="Value 2" />
<item value="3" text="Value 3" />
</root
And this code:
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
DataSourceID="XmlDataSource1"
DataTextField="text" DataValueField="value">
</asp:CheckBoxList><asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="~/Data/XMLFile.xml"></asp:XmlDataSource
--
AZ [Microsoft - .NET MVP]
Mia Home page: http://ciclismo.sitiasp.it
Asp.Net community: http://www.aspitalia.com
Il mio blog: http://blogs.aspitalia.com/az
<Lookup>
<Lookup_Entry>
<Ts>
<T>
<M>context</M>
<V>type</V>
<Va>Citizen</Va>
</T>
</Ts>
<U>.html</U>
</Lookup_Entry>
</Lookup>
example of xml file is above

code:
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/Lookup
table.xml"
XPath='/Lookup/Lookup_Entry/Ts/T/Va[../../T[M = "context" and V
= "type"]]'>
</asp:XmlDataSource>
<asp:CheckBoxList
ID="CheckBoxList1"
runat="server"
DataSourceID="XmlDataSource1">
</asp:CheckBoxList
Now how do i get each <Va> that is returned with the xmldatasource as a item
in my checkboxlist

displayed now when run is with a checkbox to the left of each item:
System.Web.UI.WebControls.XmlDataSourceNodeDescrip tor
System.Web.UI.WebControls.XmlDataSourceNodeDescrip tor
System.Web.UI.WebControls.XmlDataSourceNodeDescrip tor
System.Web.UI.WebControls.XmlDataSourceNodeDescrip tor
System.Web.UI.WebControls.XmlDataSourceNodeDescrip tor
System.Web.UI.WebControls.XmlDataSourceNodeDescrip tor
System.Web.UI.WebControls.XmlDataSourceNodeDescrip tor

mike

"Andrea Zani" wrote:

> mike <mike@.discussions.microsoft.com> ha scritto:
> > can somebody please show me some code that will let me populate a
> > checkboxlist from the xmldatasource, and have the text property set
> > to the names in the xml file
> > thanks
> With this XML file:
> <?xml version="1.0" encoding="utf-8" ?>
> <root>
> <item value="1" text="Value 1" />
> <item value="2" text="Value 2" />
> <item value="3" text="Value 3" />
> </root>
> And this code:
> <asp:CheckBoxList ID="CheckBoxList1" runat="server"
> DataSourceID="XmlDataSource1"
> DataTextField="text" DataValueField="value">
> </asp:CheckBoxList><asp:XmlDataSource ID="XmlDataSource1" runat="server"
> DataFile="~/Data/XMLFile.xml"></asp:XmlDataSource>
> --
> AZ [Microsoft - .NET MVP]
> Mia Home page: http://ciclismo.sitiasp.it
> Asp.Net community: http://www.aspitalia.com
> Il mio blog: http://blogs.aspitalia.com/az
>

Saturday, March 24, 2012

Populate dropdownlist using table data + text

I have a drop down list and the first option need to be 'ALL', then the remaining options are retrieved from a column of a table. How can this be achieved?
Thanks...I'm not sure it's the best way of doing it, but this is what I do (I'm using a DataSet, it is only mildly different with a SQLDataReader):
Dim myDS as DataSet
' Fill myDS here
Dim myDR as DataRow
myDropDownList.Items.Add(new ListItem("All"))
For Each myDR in myDS.Tables(0).Rows
myDropDownList.Items.Add(new ListItem(myDR.Items("ColumnNameOrIndexHere")))
Next
I do this because the obvious issue with using DataBind is that it flushes whatever data you already had in there. However, looking at the documentation for ListItems, it appears you can do this:
'Get data and bind it to myDropDownList (assuming you are already doing this)
myDropDownList.Items.Insert(0, new ListItem("All"))
The documentation for ListItemCollection in DropDownList (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolslistitemcollectionmemberstopic.asp) might help if neither of these are what you are looking for.

// Bind the DDL to the datasource first...
DDL.DataValueField = "value-column-name-here";
DDL.DataTextField = "text-column-name-here";
DDL.DataSource = dataTable;
DDL.DataBind();

// Add the "ALL" selection at the 1st (#0) position...
DDL.Items.Insert(0, new ListItem("ALL", "ALL"));
NC...


I think the most quicker way is to populatethe ArrayList from the Database using the SqlDataReader (In case youare using SQL Server Database).
The first element of the ArrayList will be "All" which you can simply add like this:
ArrayList a = new ArrayList();
a.Add("All");
after that you use SqlDataReader to populate the ArrayList and finally bind the list to the DropDownList.
Let me know if you need to know more about this technique!

And just how could you possibly think that going through the process of creating an ArrayList out of the data and then binding the ArrayList to the DDL be faster and better than just binding the DDL directly to the data?
NC...

It all depends on how many rows are in the Database Table and how many you are inserting in the DataSet.

In what way? Creating the ArrayList would take more time regardless, even not taking into account the GC having to be called to discard it afterwards.
NC...

DataSet is a collection of DataTables, DataRows and DataColumns so does;nt that make DataSet more heavier than an ArrayList.

Why wouldn't you just use the DataReader as the data source?
DDL.DataValueField = "value-column-name-here";
DDL.DataTextField = "text-column-name-here";
DDL.DataSource = dataReader;
DDL.DataBind();

// Add the "ALL" selection at the 1st (#0) position...
DDL.Items.Insert(0, new ListItem("ALL", "ALL"));
dataReader.Close();
Then you don't have the overhead of creating the ArrayList, or a collection of any kind. After all, you'll never need the ArrayList again after binding the DDL.
NC...


Ohh no no no!
Don't ever send the DataReader on the presentation layer. DataReaderworks while the connection is open so this means you are sending theopen connection on the presentation layer.
NEVER NEVER NEVER send the DataReader on the presentation layer. Thisis also like mixing the DataBase layer with presentation layer with noBLL in between.

azamsharp wrote:

Ohh no no no!
Don't ever send the DataReader on the presentation layer. DataReader works while the connection is open so this means you are sending the open connection on the presentation layer.
NEVER NEVER NEVER send the DataReader on the presentation layer. This is also like mixing the DataBase layer with presentation layer with no BLL in between.


Weren't you the one transferring the DataReader into an ArrayList? My data layer does nothing but produce DataTables and DataSets, so there are no Connection objects, Command objects, DataReader objects, etc in my presentation layer (nor in the entire application layer for that matter).
Here is the part that I disagree with you on:

azamsharp wrote:

I think the most quicker way is to populate the ArrayList from the Database using the SqlDataReader (In case you are using SQL Server Database).


It's no quicker to create an ArrayList than a DataTable from a DataReader (if you need the code, let me know and I'll post it). In fact, unless you create a custom class and a custom collection, you'll be very restricted with an ArrayList as you have no access to column names to attach the DataValueField and DataTextField properties of the DDL, so you'll have to use the same value for both.
NC...


>>Weren't you the one transferring the DataReader into an ArrayList?
Thats done in the business logic layer and not the presentation layer which you have demonstrated.


I would agree with azamsharp if it was an application with a static connection. However, in the case of a web page, your web server is maintaining the DB Connection either while you are populating the ArrayList from the DataReader or while performing the DataBind. No connection is maintained by the client computer, only the web server.

Well then we're talking the same thing then. My way uses a DataTable and your way uses an ArrayList. both constructed in the data layer.

The main problem, as I see it, is that using the ArrayList, you'll be restricted to one column (unless you create a custom class, stuffing that into the ArrayList, which will also take more time and code), since you have no access to column names in an ArrayList to attach to the DataValueField and DataTextField properties of the DDL, therefore, you'll have to use the same value for both.

NC...

populate text box from sql

when my page opens how i can i auto-populate a text box from a value that is passed from a stored proc?On your Form_Load, grab the data from the stored proc, set your textbox equal to the value it returns.

Wednesday, March 21, 2012

Populate textbox with textmode=password

I'm trying to populate a password style text box from information in a database. It will populate when I change it to a singleline text (or normal) but it will not with a password style. I would like it to populate with the ******* but be able to have the actual data in the background so I can submit it to a database.

ThanksWrite a code behind for this for text change event to change to * from test..

Nor text box has a property of password...

Cheers,
Devendra Naik
It's be design.. but there is a way around it.. instead of changing the Text property, you can do this:


myTextBox.Attributes["value"] = "somethingfromthedatabase";

Friday, March 16, 2012

Populating a text field and then getting its value

If I change the textbox property Readonly to false then it works perfectly
fine. I am using the latest Beta 2 release of .net framework.
Imran.

"Grant Merwitz" <grant@dotnet.itags.org.workshare.com> wrote in message
news:O0YmSUcmFHA.576@dotnet.itags.org.TK2MSFTNGP15.phx.gbl...
> Thats a strange one.
> Working fine for me:
> ASPX:
> <asp:TextBox id="TextBox1" runat="server" ReadOnly="True"
> OnClick="Button1_Click"></asp:TextBox>
> <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
> CS
> void Page_Load(object sender, System.EventArgs e)
> {
> if(!Page.IsPostBack)
> TextBox1.Text = "Hello";
> }
> void Button1_Click(object sender, System.EventArgs e)
> {
> Response.Write("Value: " + TextBox1.Text);
> }
> OUTPUT
> Value: Hello
>
> Try making a simple page like that and testing it
>
> "Imran Aziz" <imran@dotnet.itags.org.tb2.net> wrote in message
> news:e43rNIcmFHA.2860@dotnet.itags.org.TK2MSFTNGP15.phx.gbl...
>> Hello All,
>> I am populating a text field dynamic in my code, and its a read-only
>> textbox control. It populates it perfectly fine. but when I get its value
>> back in code I get an empty string any clues as to how to get this sorted
>> please ?
>>
>> Here is how I set the value of the control.
>> txtTitle.Text = feed.Channels[0].Title;
>>
>> and get it later
>>
>> String strString = txtTitle.Text;
>>
>> Any clues please ?
>>
>> Imran.
>>okay, i'm on v1.1

I have beta 2 on a machine here.
If i have time to test it before i go, i'll try run the example there

"Imran Aziz" <imran@.tb2.net> wrote in message
news:%23rwRZUdmFHA.2860@.TK2MSFTNGP15.phx.gbl...
> If I change the textbox property Readonly to false then it works
> perfectly fine. I am using the latest Beta 2 release of .net framework.
> Imran.
> "Grant Merwitz" <grant@.workshare.com> wrote in message
> news:O0YmSUcmFHA.576@.TK2MSFTNGP15.phx.gbl...
>> Thats a strange one.
>> Working fine for me:
>>
>> ASPX:
>>
>> <asp:TextBox id="TextBox1" runat="server" ReadOnly="True"
>> OnClick="Button1_Click"></asp:TextBox>
>> <asp:Button id="Button1" runat="server"
>> Text="Button"></asp:Button>
>>
>> CS
>>
>> void Page_Load(object sender, System.EventArgs e)
>> {
>> if(!Page.IsPostBack)
>> TextBox1.Text = "Hello";
>> }
>>
>> void Button1_Click(object sender, System.EventArgs e)
>> {
>> Response.Write("Value: " + TextBox1.Text);
>> }
>>
>> OUTPUT
>>
>> Value: Hello
>>
>>
>> Try making a simple page like that and testing it
>>
>>
>> "Imran Aziz" <imran@.tb2.net> wrote in message
>> news:e43rNIcmFHA.2860@.TK2MSFTNGP15.phx.gbl...
>>> Hello All,
>>> I am populating a text field dynamic in my code, and its a read-only
>>> textbox control. It populates it perfectly fine. but when I get its
>>> value back in code I get an empty string any clues as to how to get this
>>> sorted please ?
>>>
>>> Here is how I set the value of the control.
>>> txtTitle.Text = feed.Channels[0].Title;
>>>
>>> and get it later
>>>
>>> String strString = txtTitle.Text;
>>>
>>> Any clues please ?
>>>
>>> Imran.
>>>
>>
>>
Thanks a lot.
Imran.
"Grant Merwitz" <grant@.workshare.com> wrote in message
news:u9$zKbdmFHA.3936@.TK2MSFTNGP10.phx.gbl...
> okay, i'm on v1.1
> I have beta 2 on a machine here.
> If i have time to test it before i go, i'll try run the example there
> "Imran Aziz" <imran@.tb2.net> wrote in message
> news:%23rwRZUdmFHA.2860@.TK2MSFTNGP15.phx.gbl...
>> If I change the textbox property Readonly to false then it works
>> perfectly fine. I am using the latest Beta 2 release of .net framework.
>> Imran.
>>
>> "Grant Merwitz" <grant@.workshare.com> wrote in message
>> news:O0YmSUcmFHA.576@.TK2MSFTNGP15.phx.gbl...
>>> Thats a strange one.
>>> Working fine for me:
>>>
>>> ASPX:
>>>
>>> <asp:TextBox id="TextBox1" runat="server" ReadOnly="True"
>>> OnClick="Button1_Click"></asp:TextBox>
>>> <asp:Button id="Button1" runat="server"
>>> Text="Button"></asp:Button>
>>>
>>> CS
>>>
>>> void Page_Load(object sender, System.EventArgs e)
>>> {
>>> if(!Page.IsPostBack)
>>> TextBox1.Text = "Hello";
>>> }
>>>
>>> void Button1_Click(object sender, System.EventArgs e)
>>> {
>>> Response.Write("Value: " + TextBox1.Text);
>>> }
>>>
>>> OUTPUT
>>>
>>> Value: Hello
>>>
>>>
>>> Try making a simple page like that and testing it
>>>
>>>
>>> "Imran Aziz" <imran@.tb2.net> wrote in message
>>> news:e43rNIcmFHA.2860@.TK2MSFTNGP15.phx.gbl...
>>>> Hello All,
>>>> I am populating a text field dynamic in my code, and its a read-only
>>>> textbox control. It populates it perfectly fine. but when I get its
>>>> value back in code I get an empty string any clues as to how to get
>>>> this sorted please ?
>>>>
>>>> Here is how I set the value of the control.
>>>> txtTitle.Text = feed.Channels[0].Title;
>>>>
>>>> and get it later
>>>>
>>>> String strString = txtTitle.Text;
>>>>
>>>> Any clues please ?
>>>>
>>>> Imran.
>>>>
>>>
>>>
>>
>>
Sorry it took me so long to try this.

But it's working fine for me on a Machine running Beta 2

"Imran Aziz" <imran@.tb2.net> wrote in message
news:ujgDxxdmFHA.2472@.TK2MSFTNGP15.phx.gbl...
> Thanks a lot.
> Imran.
> "Grant Merwitz" <grant@.workshare.com> wrote in message
> news:u9$zKbdmFHA.3936@.TK2MSFTNGP10.phx.gbl...
>> okay, i'm on v1.1
>>
>> I have beta 2 on a machine here.
>> If i have time to test it before i go, i'll try run the example there
>>
>> "Imran Aziz" <imran@.tb2.net> wrote in message
>> news:%23rwRZUdmFHA.2860@.TK2MSFTNGP15.phx.gbl...
>>> If I change the textbox property Readonly to false then it works
>>> perfectly fine. I am using the latest Beta 2 release of .net framework.
>>> Imran.
>>>
>>> "Grant Merwitz" <grant@.workshare.com> wrote in message
>>> news:O0YmSUcmFHA.576@.TK2MSFTNGP15.phx.gbl...
>>>> Thats a strange one.
>>>> Working fine for me:
>>>>
>>>> ASPX:
>>>>
>>>> <asp:TextBox id="TextBox1" runat="server" ReadOnly="True"
>>>> OnClick="Button1_Click"></asp:TextBox>
>>>> <asp:Button id="Button1" runat="server"
>>>> Text="Button"></asp:Button>
>>>>
>>>> CS
>>>>
>>>> void Page_Load(object sender, System.EventArgs e)
>>>> {
>>>> if(!Page.IsPostBack)
>>>> TextBox1.Text = "Hello";
>>>> }
>>>>
>>>> void Button1_Click(object sender, System.EventArgs e)
>>>> {
>>>> Response.Write("Value: " + TextBox1.Text);
>>>> }
>>>>
>>>> OUTPUT
>>>>
>>>> Value: Hello
>>>>
>>>>
>>>> Try making a simple page like that and testing it
>>>>
>>>>
>>>> "Imran Aziz" <imran@.tb2.net> wrote in message
>>>> news:e43rNIcmFHA.2860@.TK2MSFTNGP15.phx.gbl...
>>>>> Hello All,
>>>>> I am populating a text field dynamic in my code, and its a
>>>>> read-only textbox control. It populates it perfectly fine. but when I
>>>>> get its value back in code I get an empty string any clues as to how
>>>>> to get this sorted please ?
>>>>>
>>>>> Here is how I set the value of the control.
>>>>> txtTitle.Text = feed.Channels[0].Title;
>>>>>
>>>>> and get it later
>>>>>
>>>>> String strString = txtTitle.Text;
>>>>>
>>>>> Any clues please ?
>>>>>
>>>>> Imran.
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
Hum strange I am doing something wrong then, I guess I will try and use
labels instead of text boxes.
Thanks a lot for coming back to me on that.

Imran
"Grant Merwitz" <grant@.workshare.com> wrote in message
news:eUjjZmNnFHA.3572@.TK2MSFTNGP09.phx.gbl...
> Sorry it took me so long to try this.
> But it's working fine for me on a Machine running Beta 2
>
> "Imran Aziz" <imran@.tb2.net> wrote in message
> news:ujgDxxdmFHA.2472@.TK2MSFTNGP15.phx.gbl...
>> Thanks a lot.
>> Imran.
>> "Grant Merwitz" <grant@.workshare.com> wrote in message
>> news:u9$zKbdmFHA.3936@.TK2MSFTNGP10.phx.gbl...
>>> okay, i'm on v1.1
>>>
>>> I have beta 2 on a machine here.
>>> If i have time to test it before i go, i'll try run the example there
>>>
>>> "Imran Aziz" <imran@.tb2.net> wrote in message
>>> news:%23rwRZUdmFHA.2860@.TK2MSFTNGP15.phx.gbl...
>>>> If I change the textbox property Readonly to false then it works
>>>> perfectly fine. I am using the latest Beta 2 release of .net framework.
>>>> Imran.
>>>>
>>>> "Grant Merwitz" <grant@.workshare.com> wrote in message
>>>> news:O0YmSUcmFHA.576@.TK2MSFTNGP15.phx.gbl...
>>>>> Thats a strange one.
>>>>> Working fine for me:
>>>>>
>>>>> ASPX:
>>>>>
>>>>> <asp:TextBox id="TextBox1" runat="server" ReadOnly="True"
>>>>> OnClick="Button1_Click"></asp:TextBox>
>>>>> <asp:Button id="Button1" runat="server"
>>>>> Text="Button"></asp:Button>
>>>>>
>>>>> CS
>>>>>
>>>>> void Page_Load(object sender, System.EventArgs e)
>>>>> {
>>>>> if(!Page.IsPostBack)
>>>>> TextBox1.Text = "Hello";
>>>>> }
>>>>>
>>>>> void Button1_Click(object sender, System.EventArgs e)
>>>>> {
>>>>> Response.Write("Value: " + TextBox1.Text);
>>>>> }
>>>>>
>>>>> OUTPUT
>>>>>
>>>>> Value: Hello
>>>>>
>>>>>
>>>>> Try making a simple page like that and testing it
>>>>>
>>>>>
>>>>> "Imran Aziz" <imran@.tb2.net> wrote in message
>>>>> news:e43rNIcmFHA.2860@.TK2MSFTNGP15.phx.gbl...
>>>>>> Hello All,
>>>>>> I am populating a text field dynamic in my code, and its a
>>>>>> read-only textbox control. It populates it perfectly fine. but when I
>>>>>> get its value back in code I get an empty string any clues as to how
>>>>>> to get this sorted please ?
>>>>>>
>>>>>> Here is how I set the value of the control.
>>>>>> txtTitle.Text = feed.Channels[0].Title;
>>>>>>
>>>>>> and get it later
>>>>>>
>>>>>> String strString = txtTitle.Text;
>>>>>>
>>>>>> Any clues please ?
>>>>>>
>>>>>> Imran.
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>

Populating a text field and then getting its value

Hello All,
I am populating a text field dynamic in my code, and its a read-only
textbox control. It populates it perfectly fine. but when I get its value
back in code I get an empty string any clues as to how to get this sorted
please ?
Here is how I set the value of the control.
txtTitle.Text = feed.Channels[0].Title;
and get it later
String strString = txtTitle.Text;
Any clues please ?
Imran.Thats a strange one.
Working fine for me:
ASPX:
<asp:TextBox id="TextBox1" runat="server" ReadOnly="True"
OnClick="Button1_Click"></asp:TextBox>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
CS
void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
TextBox1.Text = "Hello";
}
void Button1_Click(object sender, System.EventArgs e)
{
Response.Write("Value: " + TextBox1.Text);
}
OUTPUT
Value: Hello
Try making a simple page like that and testing it
"Imran Aziz" <imran@.tb2.net> wrote in message
news:e43rNIcmFHA.2860@.TK2MSFTNGP15.phx.gbl...
> Hello All,
> I am populating a text field dynamic in my code, and its a read-only
> textbox control. It populates it perfectly fine. but when I get its value
> back in code I get an empty string any clues as to how to get this sorted
> please ?
> Here is how I set the value of the control.
> txtTitle.Text = feed.Channels[0].Title;
> and get it later
> String strString = txtTitle.Text;
> Any clues please ?
> Imran.
>
If I change the textbox property Readonly to false then it works perfectly
fine. I am using the latest Beta 2 release of .net framework.
Imran.
"Grant Merwitz" <grant@.workshare.com> wrote in message
news:O0YmSUcmFHA.576@.TK2MSFTNGP15.phx.gbl...
> Thats a strange one.
> Working fine for me:
> ASPX:
> <asp:TextBox id="TextBox1" runat="server" ReadOnly="True"
> OnClick="Button1_Click"></asp:TextBox>
> <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
> CS
> void Page_Load(object sender, System.EventArgs e)
> {
> if(!Page.IsPostBack)
> TextBox1.Text = "Hello";
> }
> void Button1_Click(object sender, System.EventArgs e)
> {
> Response.Write("Value: " + TextBox1.Text);
> }
> OUTPUT
> Value: Hello
>
> Try making a simple page like that and testing it
>
> "Imran Aziz" <imran@.tb2.net> wrote in message
> news:e43rNIcmFHA.2860@.TK2MSFTNGP15.phx.gbl...
>
used the exact code, but does not work for me, the text value returned is
empty.
Imran.
"Grant Merwitz" <grant@.workshare.com> wrote in message
news:O0YmSUcmFHA.576@.TK2MSFTNGP15.phx.gbl...
> Thats a strange one.
> Working fine for me:
> ASPX:
> <asp:TextBox id="TextBox1" runat="server" ReadOnly="True"
> OnClick="Button1_Click"></asp:TextBox>
> <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
> CS
> void Page_Load(object sender, System.EventArgs e)
> {
> if(!Page.IsPostBack)
> TextBox1.Text = "Hello";
> }
> void Button1_Click(object sender, System.EventArgs e)
> {
> Response.Write("Value: " + TextBox1.Text);
> }
> OUTPUT
> Value: Hello
>
> Try making a simple page like that and testing it
>
> "Imran Aziz" <imran@.tb2.net> wrote in message
> news:e43rNIcmFHA.2860@.TK2MSFTNGP15.phx.gbl...
>
okay, i'm on v1.1
I have beta 2 on a machine here.
If i have time to test it before i go, i'll try run the example there
"Imran Aziz" <imran@.tb2.net> wrote in message
news:%23rwRZUdmFHA.2860@.TK2MSFTNGP15.phx.gbl...
> If I change the textbox property Readonly to false then it works
> perfectly fine. I am using the latest Beta 2 release of .net framework.
> Imran.
> "Grant Merwitz" <grant@.workshare.com> wrote in message
> news:O0YmSUcmFHA.576@.TK2MSFTNGP15.phx.gbl...
>
Thanks a lot.
Imran.
"Grant Merwitz" <grant@.workshare.com> wrote in message
news:u9$zKbdmFHA.3936@.TK2MSFTNGP10.phx.gbl...
> okay, i'm on v1.1
> I have beta 2 on a machine here.
> If i have time to test it before i go, i'll try run the example there
> "Imran Aziz" <imran@.tb2.net> wrote in message
> news:%23rwRZUdmFHA.2860@.TK2MSFTNGP15.phx.gbl...
>
Sorry it took me so long to try this.
But it's working fine for me on a Machine running Beta 2
"Imran Aziz" <imran@.tb2.net> wrote in message
news:ujgDxxdmFHA.2472@.TK2MSFTNGP15.phx.gbl...
> Thanks a lot.
> Imran.
> "Grant Merwitz" <grant@.workshare.com> wrote in message
> news:u9$zKbdmFHA.3936@.TK2MSFTNGP10.phx.gbl...
>
Hum strange I am doing something wrong then, I guess I will try and use
labels instead of text boxes.
Thanks a lot for coming back to me on that.
Imran
"Grant Merwitz" <grant@.workshare.com> wrote in message
news:eUjjZmNnFHA.3572@.TK2MSFTNGP09.phx.gbl...
> Sorry it took me so long to try this.
> But it's working fine for me on a Machine running Beta 2
>
> "Imran Aziz" <imran@.tb2.net> wrote in message
> news:ujgDxxdmFHA.2472@.TK2MSFTNGP15.phx.gbl...
>

Populating a textbox with a datasource

I have a textbox that needs to get it's value from database based on a value parsed from text in another textbox.

I am using a datasource with a select command to hit the database, but I have no need to collect anything but a single value, so it seems very wasteful to have to load anything into a dataset or the like, just to get that one thing to a textbox.

What's the easiest way to get this one value for the textbox?

thanks

Did you thought keep the data in a Session variable?

Your select command should similar to below

SELECT ID FROM table WHERE ID='1'

Now you could use one SqlCommand.ExecuteScalar which only returns 1 value from the database.

Check below link for more information

http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx

HC


rsegecin:

Did you thought keep the data in a Session variable?

That wouldn't do much because I wouldstill have to do all the fetching to get itinto the session variable, or any other variable for that matter.


Haissam:

Your select command should similar to below

SELECT ID FROM table WHERE ID='1'

Now you could use one SqlCommand.ExecuteScalar which only returns 1 value from the database.

Check below link for more information

http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx

HC

Yes that is very similar to the SQL I'm using

I was considering ExecuteScalar thought, the drawback is really that it's still a lot of code for one little value, and I have been reusing the datasources pretty religiously so far, eliminating the need for much code at all.

I'm hoping to keep that up, but maybe there is no particularly simple way... I wish datasources had a Scalar command that returned the value :/