Showing posts with label fields. Show all posts
Showing posts with label fields. Show all posts

Saturday, March 31, 2012

Text box looping question.

I can do this in regular asp, but i'm a little confused in .net.

There are 5 records in my table. companyid and companyname fields.

If I want to display all five records but as editable textboxes. So each textbox has the companyid from table and companyname as the text value.

Then if they hit save -- it loops through and saves all values in textboxes to the table based on the id.

Do I do put the textboxes inside a repeater?Or do I put the textboxes inside a datalist and do it that way. I'm not sure about the saving procedure.
I think you can use a repeater,

try this (this should definitely work :)):


<asp:Repeater id="myRptr" runat="server">
<ItemTemplate>
<input type=text id='<%# DataBinder.Eval(Container.DataItem, "companyid ") %>'
value='<%# DataBinder.Eval(Container.DataItem, "companyname") %>'>
</ItemTemplate>
</asp:Repeater>

It didn't like that ('<%# DataBinder.Eval(Container, "DataItem.company_id") %>' is not a valid identifier.) so I tried:

<asp:TextBox id="txtName" runat="server" text='<%# DataBinder.Eval(Container, "DataItem.company_name") %>'></asp:TextBox>
<asp:Label ID="lblName" Runat="server" text=<%# DataBinder.Eval(Container, "DataItem.company_id") %>></asp:Label
Then in codebehind
Dim j As RepeaterItem
For Each j In rptName.Items
Response.Write(DirectCast(j.FindControl("txtName"), TextBox).Text & "<br>")
Response.Write(DirectCast(j.FindControl("lblName"), Label).Text & "<br>")
Next

That gives me the companyname and id. Then I can just use update statement in the [for...next] and update.
I tried this way instead and it seems to work.

<asp:TextBox id="txtName" runat="server" text='<%# DataBinder.Eval(Container, "DataItem.company_name") %>'></asp:TextBox>
<asp:Label ID="lblName" Runat="server" text=<%# DataBinder.Eval(Container, "DataItem.company_id") %>></asp:Label
Dim j As RepeaterItem
For Each j In rptName.Items
Response.Write(DirectCast(j.FindControl("txtName"), TextBox).Text & "<br>")
Response.Write(DirectCast(j.FindControl("lblName"), Label).Text & "<br>")
Next
Then I just use update statement inside [for ... next]
You can use either... Repeater is a lighter control though...

All the form data will be post back (there is no looping concept)

You can read a very good MSDN article on control choice here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/aspnet-whenusedatawebcontrols.asp

Good luck :)
I used:


<asp:TextBox id="txtName" runat="server" text='<%# DataBinder.Eval(Container, "DataItem.company_name") %>'></asp:TextBox>
<asp:Label ID="lblName" Runat="server" text=<%# DataBinder.Eval(Container, "DataItem.company_id") %>></asp:Label>

Behind file


Dim j As RepeaterItem
For Each j In rptName.Items
Response.Write(DirectCast(j.FindControl("txtName"), TextBox).Text & "<br>")
Response.Write(DirectCast(j.FindControl("lblName"), Label).Text & "<br>")
Next

I dont know why you have to do this...

I tested this code piece before i posted it and it works fine with me I do not have to use the DirectCast and all that...

Simple '<%# DataBinder.Eval(Container, "DataItem.company_id") %>' works !!!

Did you databind the repeater to a datasource in the Page_Load ?
What does your [for ...next] loop look like?
I tried it with <asp:textbox not with a regular input box like you have. Sorry. So it will work the way you said.
I call this after I hit save to get the values:

Dim j As RepeaterItem
For Each j In rptName.Items
Response.Write(DirectCast(j.FindControl("txtName"), TextBox).Text & "<br>")
Response.Write(DirectCast(j.FindControl("lblName"), Label).Text & "<br>")
Next

How would you get the values using your way?
Oh yes... about the code behind... you will have to do the FindControl...

I am not sure why you are using 'DirectCast(j.FindControl("txtName")... ' what if you use
this.FindControl("txtName")

I might be wrong... cause I am not sure why you need the DirectCast function...

Let me know

Wednesday, March 28, 2012

Text boxes and read-only text

I'm wondering what standard/best practices are for the following scenario:
I have a page representing several fields for stored data. If the user has
sufficient access privileges, the page is rendered w/ read/write text boxes
and
they can edit the various fields as needed. However, if the user doesn't ha
ve
sufficient privileges (i.e. view only), the page is rendered w/ the text box
es
set to read-only. However, this results in a rather clunky looking page, an
d
if there is more text in a box than can be rendered w/i the specified box
height, then the user must scroll. Further, when printing the page, the tex
t
is clipped to the box.
So, my thought has been to re-design the page to use two different controls
for
each text field: a text box for read/write, and a label (static text) for
read-only. My thought that it will result in a much cleaner view page, and
printing will be as expected. The negative is that there are then two contr
ols
for each field, and I must hide/show the appropriate control depending on th
e
read-write/read-only status.
Is there a better way to do this that doesn't rely on two controls for each
control?
Thanks for any thoughts and insights.What is your browser base?
If you know that it is IE only..
check out contenteditable... basically it allows any html element to be
editable..
http://msdn.microsoft.com/library/d...enteditable.asp
so you could do
<div contenteditable="true">This text it editable</div>
for those that have read write..
then simply change the flag to false if it is readonly,
This means printing doesnt get cliped either.
To make it so that you can still reference input ins your code you can do
<div contenteditable="true" id="Body" onpropertychange="BodyInput.value =
this.innerText;">This text it editable</div>
<input type="hidden" name="BodyInput" value="">
then you simple get the data from the this.BodyInput.value property on the
server.
Not sure if this is what you are after but it may give you ideas as to where
to go from here.
"Julie" <julie@.nospam.com> wrote in message
news:40A1967F.D6ACF7C2@.nospam.com...
> I'm wondering what standard/best practices are for the following scenario:
> I have a page representing several fields for stored data. If the user
has
> sufficient access privileges, the page is rendered w/ read/write text
boxes and
> they can edit the various fields as needed. However, if the user doesn't
have
> sufficient privileges (i.e. view only), the page is rendered w/ the text
boxes
> set to read-only. However, this results in a rather clunky looking page,
and
> if there is more text in a box than can be rendered w/i the specified box
> height, then the user must scroll. Further, when printing the page, the
text
> is clipped to the box.
> So, my thought has been to re-design the page to use two different
controls for
> each text field: a text box for read/write, and a label (static text) for
> read-only. My thought that it will result in a much cleaner view page,
and
> printing will be as expected. The negative is that there are then two
controls
> for each field, and I must hide/show the appropriate control depending on
the
> read-write/read-only status.
> Is there a better way to do this that doesn't rely on two controls for
each
> control?
> Thanks for any thoughts and insights.
Darren Clark wrote:
> What is your browser base?
> If you know that it is IE only..
> check out contenteditable... basically it allows any html element to be
> editable..
> http://msdn.microsoft.com/library/d...enteditable.asp
> so you could do
> <div contenteditable="true">This text it editable</div>
> for those that have read write..
> then simply change the flag to false if it is readonly,
> This means printing doesnt get cliped either.
> To make it so that you can still reference input ins your code you can do
> <div contenteditable="true" id="Body" onpropertychange="BodyInput.value =
> this.innerText;">This text it editable</div>
> <input type="hidden" name="BodyInput" value="">
> then you simple get the data from the this.BodyInput.value property on the
> server.
> Not sure if this is what you are after but it may give you ideas as to whe
re
> to go from here.
Thanks for the link and info, I'll look into it.
And, yes, my target is IE.

Text boxes and read-only text

I'm wondering what standard/best practices are for the following scenario:

I have a page representing several fields for stored data. If the user has
sufficient access privileges, the page is rendered w/ read/write text boxes and
they can edit the various fields as needed. However, if the user doesn't have
sufficient privileges (i.e. view only), the page is rendered w/ the text boxes
set to read-only. However, this results in a rather clunky looking page, and
if there is more text in a box than can be rendered w/i the specified box
height, then the user must scroll. Further, when printing the page, the text
is clipped to the box.

So, my thought has been to re-design the page to use two different controls for
each text field: a text box for read/write, and a label (static text) for
read-only. My thought that it will result in a much cleaner view page, and
printing will be as expected. The negative is that there are then two controls
for each field, and I must hide/show the appropriate control depending on the
read-write/read-only status.

Is there a better way to do this that doesn't rely on two controls for each
control?

Thanks for any thoughts and insights.What is your browser base?

If you know that it is IE only..

check out contenteditable... basically it allows any html element to be
editable..
http://msdn.microsoft.com/library/d...enteditable.asp

so you could do
<div contenteditable="true">This text it editable</div>
for those that have read write..
then simply change the flag to false if it is readonly,

This means printing doesnt get cliped either.

To make it so that you can still reference input ins your code you can do

<div contenteditable="true" id="Body" onpropertychange="BodyInput.value =
this.innerText;">This text it editable</div>
<input type="hidden" name="BodyInput" value=""
then you simple get the data from the this.BodyInput.value property on the
server.

Not sure if this is what you are after but it may give you ideas as to where
to go from here.

"Julie" <julie@.nospam.com> wrote in message
news:40A1967F.D6ACF7C2@.nospam.com...
> I'm wondering what standard/best practices are for the following scenario:
> I have a page representing several fields for stored data. If the user
has
> sufficient access privileges, the page is rendered w/ read/write text
boxes and
> they can edit the various fields as needed. However, if the user doesn't
have
> sufficient privileges (i.e. view only), the page is rendered w/ the text
boxes
> set to read-only. However, this results in a rather clunky looking page,
and
> if there is more text in a box than can be rendered w/i the specified box
> height, then the user must scroll. Further, when printing the page, the
text
> is clipped to the box.
> So, my thought has been to re-design the page to use two different
controls for
> each text field: a text box for read/write, and a label (static text) for
> read-only. My thought that it will result in a much cleaner view page,
and
> printing will be as expected. The negative is that there are then two
controls
> for each field, and I must hide/show the appropriate control depending on
the
> read-write/read-only status.
> Is there a better way to do this that doesn't rely on two controls for
each
> control?
> Thanks for any thoughts and insights.
Darren Clark wrote:
> What is your browser base?
> If you know that it is IE only..
> check out contenteditable... basically it allows any html element to be
> editable..
> http://msdn.microsoft.com/library/d...enteditable.asp
> so you could do
> <div contenteditable="true">This text it editable</div>
> for those that have read write..
> then simply change the flag to false if it is readonly,
> This means printing doesnt get cliped either.
> To make it so that you can still reference input ins your code you can do
> <div contenteditable="true" id="Body" onpropertychange="BodyInput.value =
> this.innerText;">This text it editable</div>
> <input type="hidden" name="BodyInput" value="">
> then you simple get the data from the this.BodyInput.value property on the
> server.
> Not sure if this is what you are after but it may give you ideas as to where
> to go from here.

Thanks for the link and info, I'll look into it.

And, yes, my target is IE.

Tuesday, March 13, 2012

TextBox and popup Grid (other .aspx)

In .aspx page I have ASP.NET
1TextBox(txtFirst) 1 Button (btnSearch)
1 TextboxtxtLast) and a MS SQL DB (Table with the fields First Name, and Last Name)
What I want it is:
- I want to enter some text in first TextBox
-After I clicked btnSearch to jump in other .aspx with a Data Grid
-After I browse what I want, I will choose a Last Name.
-After Selection I want to put the data from the Grid in both TextBoxes
Please! Thanks.I'm on chapter 5 of the book you have just requested but in the meantime I recommend you pay 4guys a visit and read some of the excellent tutorials on asp.net, in particular the stuff on datagrids and other server controls - http://www.4guysfromrolla.com - what you want to do is quite involved and would take some time to explain what is already well documented on the net.