Showing posts with label field. Show all posts
Showing posts with label field. Show all posts

Thursday, March 29, 2012

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.

Saturday, March 24, 2012

Populate foreign key in InsertTemplate of FormView

Hello all,

How would I populate a foreign key value in a label field of a FormView when
FormView changes mode to Insert? So that I can insert foreign key.

Explanation:
Suppose there are two tables in database, EMPLOYEE (list of employees) and
EMPLOYEE_DOCS (list of documents of every employee). table EMPLOYEE_DOCS
have a foreign key field EMPLOYEE_ID. When I use FormView's Insert mode for
EMPLOYEE_DOCS, I want to to explicitly take foreign key, so that it wont go
blank when inserting in database or user wont need to type it. I have
everything in Panels (webcontrol)

Thank you for help.
MirajThanks all, I figured out

I did this:

Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.FormViewInsertEventArgs) Handles
FormView1.ItemInserting

e.Values("EMPLOYEE_ID") =
GridView1.Rows(GridView1.SelectedIndex).Cells(1).T ext ' cells(1).text is the
foreign key

End Sub

"Miraj Haq" <mirajhaq-n-o-s-p-a-m@.yahoo.com> wrote in message
news:epbuhXYhFHA.1444@.TK2MSFTNGP10.phx.gbl...
> Hello all,
> How would I populate a foreign key value in a label field of a FormView
> when FormView changes mode to Insert? So that I can insert foreign key.
> Explanation:
> Suppose there are two tables in database, EMPLOYEE (list of employees) and
> EMPLOYEE_DOCS (list of documents of every employee). table EMPLOYEE_DOCS
> have a foreign key field EMPLOYEE_ID. When I use FormView's Insert mode
> for EMPLOYEE_DOCS, I want to to explicitly take foreign key, so that it
> wont go blank when inserting in database or user wont need to type it. I
> have everything in Panels (webcontrol)
> Thank you for help.
> Miraj

Populate insert form field from GridView selection

Hi,

I'm trying to do something that seems like it should be simple, but I'm having trouble getting it to work. I have a page with a GridView and a FormView in Insert mode.

When the user selects a row in the gridview, I want to take the data keys from that selection and populate them to the appropriate textboxes in the form. I'm trying to do this in the

"GridView1_SelectedIndexChanged event" with the following code:

TextBox t;

t = (TextBox)FormView1.FindControl("myTextBox");

t.Text = (String)GridView1.SelectedDataKey.Values[0];

The text in "myTextBox" doesn't change, it remains blank. I've tried to find another event in which to put this code but so far no luck. I'm a newbie so I'm sure it's something obvious.

Can anyone help me with this? Thanks in advance.

Try moving your code to the FormView.DataBound event.


Hi Ed,

When I do that, I get "Object reference not set to an instance of an object. " I'm guessing that this is because the formview1_databound fires when the page is first loading, before there is a selected key from the gridview. I'm not sure that this is the case, it's just my best guess.

Do you have any suggestion for a workaround or alternate approach?

Thanks.


Once try this

ProtectedSub GridView1_SelectedIndexChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles GridView1.SelectedIndexChanged

Formview1.PageIndex = GridView1.SelectedIndex

EndSub


Hi Mahesh,

Okay, now I have this code but I still don't see the text I want populated into the text box. What am I doing wrong?

protectedvoid GridView1_SelectedIndexChanged(object sender,EventArgs e)

{

FormView1.PageIndex = GridView1.SelectedIndex;

TextBox t;

t = (TextBox)FormView1.FindControl("myTextBox");

t.Text = (String)GridView1.SelectedDataKey.Values[0];

}


How about this:


protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{

for (int i = 0; i < GridView1.Rows.Count; i++)
{
if (GridView1.SelectedIndex == i)
{
TextBox t;

t = (TextBox)FormView1.FindControl("myTextBox");
t.Text = (String)GridView1.SelectedDataKey.Values[0];
}
}
}


Within your FormView.DataBound event, simply place a conditional statement which checks for the existence of a SelectedItem.

if (!GridView1.SelectedIndex.Equals(-1))


That did it! Thanks very much (I told you that I was a newbie :-).

Wednesday, March 21, 2012

populating a drop down box with ms access information

what is the best way to populate a drop down box with a list of names in a database? i'm using webmatrix/asp.net and the names are in a field called "name" .

dim ConnString as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MyDBPath;"
dim conn As System.Data.OleDb.OleDbConnection(ConnString)
dim cmd As New OleDb.OleDbCommand()
dim dr as OleDb.OleDbDataReader
cmd.connection = conn
cmd.CommandType = CommandType.Text
cmd.CommandText = "select id, name from mytable"
try
conn.open
dr = cmd.executereader() 'assuming dr is your datareader
myDropDownList.datasource = dr
myDropDownList.DataTextField = "name"
myDropDownList.DataValueField = "id" 'example of assinging a value field too
myDropDownList.Databind()
finally
conn.close
end try

This is an example using a datareader for quick access and ideal for dropdownlists. You will see examples using datasets too but this just happens to be my preference from a performance point of view.

Populating a DropDownList

Hi all,
I have a MS SQLServer database which has two tables, 'images' and
'photographers'. The photographer table contains a field for
PhotographerID and a one for PhotographerName. The image table also
contains a field for photographerID which is used to join the two
tables.
I'm having problems with populating a dropDownList using the complete
set of photographerNames and IDs from the 'photographer' table but
binding the selected value to the Image table.
I've set up a DataSet and added both tables to it and now have the list
populated but can't bind the list to the photographerID field in the
'image' table.
Anyone done anything like this before? if so any help would be much
appreciated,
thanks in advance,
PaulSo if i understand, you have a Dataset with 2 DataTables.
The DataMember property of the Dropdownlist object will allow you to specify
which dataTable to use from the datasource which is in this case the DataSet
So for example
DropDownList dll = new DropDownList();
ddl.DataSource = MyDataSetWith2Tables;
ddl.DataMember = "Photographers"
...
ddl.DataBind()
HTH,
Tony
"p.mc" <paul.mcmanus.uk@.googlemail.com> wrote in message
news:1142616298.580083.168470@.j33g2000cwa.googlegroups.com...
> Hi all,
> I have a MS SQLServer database which has two tables, 'images' and
> 'photographers'. The photographer table contains a field for
> PhotographerID and a one for PhotographerName. The image table also
> contains a field for photographerID which is used to join the two
> tables.
> I'm having problems with populating a dropDownList using the complete
> set of photographerNames and IDs from the 'photographer' table but
> binding the selected value to the Image table.
> I've set up a DataSet and added both tables to it and now have the list
> populated but can't bind the list to the photographerID field in the
> 'image' table.
> Anyone done anything like this before? if so any help would be much
> appreciated,
> thanks in advance,
> Paul
>
Hi Tony,
thanks for your help, however i'm still unable to get it working as i
would like. Using the method you suggested i've got the ddl displaying
the complete list of photographers from the photographers table. After
i select this i would like to store the result (photog ID) in the
photographerID field in the 'imageTable'. So i guess i need to bind the
DataTextField and DataValueField to the photographer Table but bind the
result to the image table.
I'm sure i must be missing something simple here, but can't think what
it is. Any further help would be appreciated.
thanks, paul
Anthony Merante wrote:
> So if i understand, you have a Dataset with 2 DataTables.
> The DataMember property of the Dropdownlist object will allow you to speci
fy
> which dataTable to use from the datasource which is in this case the DataS
et
> So for example
> DropDownList dll = new DropDownList();
> ddl.DataSource = MyDataSetWith2Tables;
> ddl.DataMember = "Photographers"
> ...
> ddl.DataBind()
> HTH,
> Tony
> "p.mc" <paul.mcmanus.uk@.googlemail.com> wrote in message
> news:1142616298.580083.168470@.j33g2000cwa.googlegroups.com...
Assuming that the image field that you want to place in selected value
is of type System.String, you need to create a SQL statement or
(preferably) a stored procedure that will do the join. Then bind the
dropdown list to that...
using (SqlConnection conPhotographerAndImage = new
SqlConnection([PUT CONNECTION STRING HERE])
{
SqlCommand cmdGet = new
SqlCommand("GetPhotographersAndImages", conPhotographerAndImage);
cmdGet.CommandType = CommandType.StoredProcedure;
//You could also omit the above line and set command with
text instead...
//SELECT p.PhotographerName,i.ImageName FROM Photographer
p INNER JOIN Image i ON p.PhotographerId=i.PhotographerId;
conPhotographerAndImage.Open();
SqlDataReader drdPhotographerAndImage =
cmdGet.ExecuteReader();
this.ddlMyDropDownList.DataSource =
drdPhotographerAndImage;
this.ddlMyDropDownList.DataValueField = "ImageName";
this.ddlMyDropDownList.DataTextField =
"PhotographerName";
this.ddlMyDropDownList.DataBind();
drdPhotographerAndImage.Close();
conPhotographerAndImage.Close();
ListItem lstAll = new ListItem("[all]", "999999");
this.ddlEventType.Items.Insert(this.ddlEventType.Items.Count, lstAll);
this.ddlEventType.SelectedIndex =
this.ddlEventType.Items.Count - 1;
}
HTH,
JP
JP
thanks for your help, just to clarify - i've included a table in the
dataSet which is a SQL view that contains the INNER JOIN you suggest.
Is it necessary to explicitly create this join for the ddl?
The webForm i'm working on will contain 15 to 20 of these foreign-key
joins bound to ddls.
I'm sure that what i'm trying to do must be a very common technique (is
it not one of the basic principles of relational databases?), surely
using foreign keys to link to other tables can be handled more
efficiently than this?
thanks again
The point is to set the datasource up as *one* entity (not two tables).
This where the join comes in. You configure the query with a join to
return a result set that has all of your data. You then simply set
DataTextField to the name of the field that you want to show in the
dropdown, set DataValue field to the name of the field that you want to
be in the corresponding values, and then bind the DDL to the one
entity. At least that's the way I have always done it.
JP
Thanks for your help, much appreciated.
I'll have a go and see where i get,
thanks again

Populating a DropDownList

Hi all,

I have a MS SQLServer database which has two tables, 'images' and
'photographers'. The photographer table contains a field for
PhotographerID and a one for PhotographerName. The image table also
contains a field for photographerID which is used to join the two
tables.

I'm having problems with populating a dropDownList using the complete
set of photographerNames and IDs from the 'photographer' table but
binding the selected value to the Image table.

I've set up a DataSet and added both tables to it and now have the list
populated but can't bind the list to the photographerID field in the
'image' table.

Anyone done anything like this before? if so any help would be much
appreciated,

thanks in advance,

PaulSo if i understand, you have a Dataset with 2 DataTables.

The DataMember property of the Dropdownlist object will allow you to specify
which dataTable to use from the datasource which is in this case the DataSet

So for example

DropDownList dll = new DropDownList();
ddl.DataSource = MyDataSetWith2Tables;
ddl.DataMember = "Photographers"
...
ddl.DataBind()

HTH,
Tony

"p.mc" <paul.mcmanus.uk@.googlemail.com> wrote in message
news:1142616298.580083.168470@.j33g2000cwa.googlegr oups.com...
> Hi all,
> I have a MS SQLServer database which has two tables, 'images' and
> 'photographers'. The photographer table contains a field for
> PhotographerID and a one for PhotographerName. The image table also
> contains a field for photographerID which is used to join the two
> tables.
> I'm having problems with populating a dropDownList using the complete
> set of photographerNames and IDs from the 'photographer' table but
> binding the selected value to the Image table.
> I've set up a DataSet and added both tables to it and now have the list
> populated but can't bind the list to the photographerID field in the
> 'image' table.
> Anyone done anything like this before? if so any help would be much
> appreciated,
> thanks in advance,
> Paul
Hi Tony,

thanks for your help, however i'm still unable to get it working as i
would like. Using the method you suggested i've got the ddl displaying
the complete list of photographers from the photographers table. After
i select this i would like to store the result (photog ID) in the
photographerID field in the 'imageTable'. So i guess i need to bind the
DataTextField and DataValueField to the photographer Table but bind the
result to the image table.

I'm sure i must be missing something simple here, but can't think what
it is. Any further help would be appreciated.

thanks, paul

Anthony Merante wrote:
> So if i understand, you have a Dataset with 2 DataTables.
> The DataMember property of the Dropdownlist object will allow you to specify
> which dataTable to use from the datasource which is in this case the DataSet
> So for example
> DropDownList dll = new DropDownList();
> ddl.DataSource = MyDataSetWith2Tables;
> ddl.DataMember = "Photographers"
> ...
> ddl.DataBind()
> HTH,
> Tony
> "p.mc" <paul.mcmanus.uk@.googlemail.com> wrote in message
> news:1142616298.580083.168470@.j33g2000cwa.googlegr oups.com...
> > Hi all,
> > I have a MS SQLServer database which has two tables, 'images' and
> > 'photographers'. The photographer table contains a field for
> > PhotographerID and a one for PhotographerName. The image table also
> > contains a field for photographerID which is used to join the two
> > tables.
> > I'm having problems with populating a dropDownList using the complete
> > set of photographerNames and IDs from the 'photographer' table but
> > binding the selected value to the Image table.
> > I've set up a DataSet and added both tables to it and now have the list
> > populated but can't bind the list to the photographerID field in the
> > 'image' table.
> > Anyone done anything like this before? if so any help would be much
> > appreciated,
> > thanks in advance,
> > Paul
Assuming that the image field that you want to place in selected value
is of type System.String, you need to create a SQL statement or
(preferably) a stored procedure that will do the join. Then bind the
dropdown list to that...

using (SqlConnection conPhotographerAndImage = new
SqlConnection([PUT CONNECTION STRING HERE])
{
SqlCommand cmdGet = new
SqlCommand("GetPhotographersAndImages", conPhotographerAndImage);
cmdGet.CommandType = CommandType.StoredProcedure;

//You could also omit the above line and set command with
text instead...
//SELECT p.PhotographerName,i.ImageName FROM Photographer
p INNER JOIN Image i ON p.PhotographerId=i.PhotographerId;

conPhotographerAndImage.Open();

SqlDataReader drdPhotographerAndImage =
cmdGet.ExecuteReader();

this.ddlMyDropDownList.DataSource =
drdPhotographerAndImage;
this.ddlMyDropDownList.DataValueField = "ImageName";
this.ddlMyDropDownList.DataTextField =
"PhotographerName";
this.ddlMyDropDownList.DataBind();

drdPhotographerAndImage.Close();
conPhotographerAndImage.Close();

ListItem lstAll = new ListItem("[all]", "999999");

this.ddlEventType.Items.Insert(this.ddlEventType.I tems.Count, lstAll);
this.ddlEventType.SelectedIndex =
this.ddlEventType.Items.Count - 1;
}

HTH,
JP
JP

thanks for your help, just to clarify - i've included a table in the
dataSet which is a SQL view that contains the INNER JOIN you suggest.
Is it necessary to explicitly create this join for the ddl?

The webForm i'm working on will contain 15 to 20 of these foreign-key
joins bound to ddls.

I'm sure that what i'm trying to do must be a very common technique (is
it not one of the basic principles of relational databases?), surely
using foreign keys to link to other tables can be handled more
efficiently than this?

thanks again
The point is to set the datasource up as *one* entity (not two tables).
This where the join comes in. You configure the query with a join to
return a result set that has all of your data. You then simply set
DataTextField to the name of the field that you want to show in the
dropdown, set DataValue field to the name of the field that you want to
be in the corresponding values, and then bind the DDL to the one
entity. At least that's the way I have always done it.

JP
Thanks for your help, much appreciated.
I'll have a go and see where i get,
thanks again

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 Drop Down List

Hi,

I have a drop down list which is bound to a database field and is populated from so. However I want to add 1 of my own items to the drop down list no matter what is in the database. Is this possible?

ThanksYes. You can use the .Items.Add or .Items.Insert to add items to the dropdownlist. Just be sure to do this after you bind your data, because the bind will remove all items from the list.

hope this helps,
sivilian
Thanks very much, solved my problem.
Well the method is working but how we can set the additional item at the top, for example set "Select one State" on top of my drop down.

Thanks
Hello, try that in the page_load:

ddl.Items.Insert(new ListItem("text",value"),0);

regards
Thanks for you time,

Overload resolution failed because no accessible 'Insert' can be called with these arguments:

the aforsaid error return on line

AltShippingAdd.Items.Insert(new ListItem("Carbon", "C"),0);

Thanks in Advance
Hello,

this working fine, i think there is some problem in syntex.

AltShippingAdd.Items.Insert(0, New ListItem("Select One"))

the above statement is working fine but we can't able to define the value of that item is there a way to define the value of this item.

Thanks.
oh! in advance.
Hello, maybe you are right, I messed up with the syntax. but try to have:

AltShippingAdd.Items.Inert(0,new ListItem("Select One","1"))

regards
Thanks Bilal
It works fine
I am glad I was able to help you out my friend. For any further help, please dont hesitate to contact me here at the forums.

regards