Set TextBox text value to value from DataList Control

I'm sure this is a totally sad question to ask, but...

I am using a DataList View to display data. I have a separate form within a LoginView that I would like to use to update a few main fields.

I want to set the Text property of the TextBox in my custom edit form to the value of the corresponding field in the DataList. Is this possible?

0
nateborland
7/26/2007 6:10:21 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

6 Replies
1051 Views

Similar Articles

[PageSpeed] 34

I think i get your question --> you want the text from a  textbox from the datalist to be input into a textbox within your form?

try:
TextBox tb = DataList1.FindControl("TextBoxIDToFind");

TextBoxOnForm.Text = tb.Text;


David Kiff
http://DavidKiff.co.uk

-- "Mark As Answer" If my reply helped you --
0
DavidKiff
7/26/2007 6:50:20 PM

I'm trying your solution, which makes perfect sense to me, but for some reason I keep getting "Object reference not set to an instance of an object"

My code:

TextBox d = LoginView1.FindControl("txtCopsNotes") as TextBox;

Label i = DataList1.FindControl("copsnotesLabel") as Label;

d.Text = i.Text;

Any ideas?

0
nateborland
7/26/2007 7:37:09 PM

Are the controls within a container? (such as an asp:panel)

if they are then you will have to do:

TextBox d = LoginView1.FindControl("ContainerID").FindControl("txtCopsNotes") as TextBox;

which one is recieveing the error?  If you didnt realse the error basically means the item cant be found !:)


David Kiff
http://DavidKiff.co.uk

-- "Mark As Answer" If my reply helped you --
0
DavidKiff
7/26/2007 9:18:33 PM

Trying something similar - and yes, the Control is within a container (UpdatePanel, then DataList)

Trying:

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

{

if (User.IsInRole("Administrators"))

{

DataList1.FindControl(
"Button1").Visible = true;

UpdatePanel1.Update();

}

 

This is causing the not set to an instance error.

0
nateborland
7/27/2007 3:41:21 PM

Hi:

nateborland:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

{

if (User.IsInRole("Administrators"))

{

DataList1.FindControl(
"Button1").Visible = true;

UpdatePanel1.Update();

}

 

This is causing the not set to an instance error.

  Please use:

DataList1..Items[index].FindControl("Button1").Visible = true; //You can use a loop to do this.

  If your problem isn't solved, please inform us.

Regards

 

 


Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Allen
7/30/2007 9:01:58 AM

nateborland:

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

DataList1.FindControl("Button1").Visible = true;

}

Is it GridView control or DataList control?

Take DataList for example, if you want to get the TextBox which is located in Template,

You should get the Item first, like

    Protected Sub DataList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataList1.SelectedIndexChanged
        DataList1.SelectedItem.FindControl("TextBox1").Visible = False
        DataList1.Items(1).FindControl("TextBox1").Visible = False
    End Sub
 Hope it helps.
Sincerely,
Techie Zhang
Microsoft Online Community Support
0
Techie
7/30/2007 9:40:58 AM
Reply:

Similar Artilces:

setting non server control values: input type="text" how to set value programmatically?
<form id="someForm" runat="server" enableviewstate="true">  <input id="manualtextbox" type="text" value="abc" name="manualtextbox" /></form> I have access to user supplied value via: string userEnteredThisInForm = Request.Params["manualtextbox"] but, how can I set the value when sending form back to browser? If it's not runat="server" then you'll have to emit javascript to set the value: document.getElementById('manualtextbox').value = '<desired value>'; add runat="sever" to the control  <input id="manualtextbox" type="text" value="abc" name="m...

Control.Value and Control.SelectedItem.Value
Can someone explain to me the difference between say, Dropdownlist.SelectedItem.Value and Dropdownlist.SelectedValue?? Just curious, Thanks!Tim These are going to return the same thing. dropdownlist.selectedvalue is a shortcut to get the currently selected value in the dropdown. If that is all you want then you can just use that. If you want to access the currently selected item you can use dropdownlist.selecteditem and that return the item and you can then access any of the item's properties, including in this case the value property. If this post answered your question please r...

Setting the text value of a textbox control in a datagrid -without- databinding.
Hello,I'm currently having trouble setting the text value of a textbox control within a datagrid without using the databind technique.  I've never had to do this before, I've only had to databind and read values so I have no idea how to do this.  The method I use to read values doesn't allow me to set them at all unfortunately.I've found a very sketchy work around using javascript and images but this would cause a lot of problems and having a clean cut way through this (since it's only one line of code giving trouble) would result in a much more stable and understandable project.Th...

using javascript getting value from textbox when edit button is clicked and both controls are present in gridview control
Hi All using javascript I want to get value  from textbox when edit button is clicked and both controls that is texbox and button are present in gridview control .Alok Hi aloksinha83, Please see this post: http://forums.asp.net/t/1069245.aspx Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

when loading a previously created record on to form, some controls are missing values(controls are depended on values selected in other controls)
Hello - I have created a page for Editing records.  this page will open up a chosen record and allow user to edit the data.On the form, I have 3 drop down lists.   The second dropdown list should fill values depending on value chosen in first dropdown list.  The third dropdown list should show/fill values depending on value chosen in second dropdown list.So taking this into count, i have several records with various data.  When I open-up/load a record in Edit form, only the first dropdown list has a value selected that was the pre-existing va...

new to .net, need help setting db values from checkbox's then retrieving value to a label control
Hi, Being new to asp.net i know this possible i just can't quite get it right!  I need a page with 5 checkbox's that when submitted sets the bit values in DB fields to checked. Then i need another page that retrieves the records of the checkboxes, but instead of having the db pre-set checkboxes on the second page i want it to turn on label web controls depending on if the check box is set.. I hope that makes sense?!! Can anyone point me in the right direction or to a suitable tutorial? Thanks in advance Ben Excellent article here.http://www.heliosfx.com...

Setting Value of Control in a DataList
Hey experts,  I'm trying to set the value of some Radio Buttons to be checked based on some criterias on Page Load. ((RadioButton)DataList1.Items[1].FindControl("rbScore5")).Checked = true; If i use that code under Page_Load or any other event it dosen't do anything.  But if i use it on button click it works.   protected void Button1_Click(object sender, EventArgs e) { ((RadioButton)DataList1.Items[1].FindControl("rbScore5")).Checked = true; }   Any reasons why?  How can I set the values on Page Load?   Thanks in advance. sorry...i double post...

Setting parent control values from user control
Hi there, I'm having a little trouble with user controls...Basically I have an aspx page with a number of components on it. On the page load, I want to call a function in an external (reusable) class or control to set the text of all the buttons on the aspx page.I've tried to use a user control to do this using the following:The user control has one function in it, in the C# behind --public void setText(){ for(int i = 0; i < this.Controls.Count; i++){      String type = this.Controls[ i ].GetType().ToString();     &nbs...

setting value of control in datalist
Hey experts,  I'm trying to set the value of some Radio Buttons to be checked based on some criterias on Page Load. ((RadioButton)DataList1.Items[1].FindControl("rbScore5")).Checked = true; If i use that code under Page_Load or any other event it dosen't do anything.  But if i use it on button click it works.   protected void Button1_Click(object sender, EventArgs e) { ((RadioButton)DataList1.Items[1].FindControl("rbScore5")).Checked = true; }   Any reasons why?  How can I set the values on Page Load?   Thanks in advance. I think you are tryin...

Setting values for controls in a Datalist
Hello all, I have a DataList with a label in the footer that I need to update the .Text value of. How can I access that control and insert new text? I would be wrapping is in an AJAX UpdatePanel so it appears seamless. Something like this: <asp:DataList ID="DataList1" runat="server">      <FooterTemplate>           <asp:Label ID="statusBar" runat="server" />      </FooterTemplate> </asp:DataList> Then in the code behind have this: ...

Pass 1 control value to another control value
I have this form, is the detailsview, and in edit mode, I have a link that you click to open up a small dhtml window (not a new window but more like a layer so everything is on the same page).  When I select an item from the dhtml window, it puts the value into a textbox.  I then have a button I click and I want to pass that value from that textbox to the textbox in the detailsview.  When I click the button, the value is not passed. Here is the code I use for getting the value from the dhtml window and assigning it to the detailsview textbox: If e.CommandName = "pi...

The value set to controls at client side donot persist for each page load, else it is again set to the default value...??
 I am trying to set date to the textbox field using javascript (Client side), the function is as follows. function From_calendarPicker(){                                var    sDPath = "../Calender.aspx";                 var    oWin = window.showModalDialog(sDPath, null, "dialogWidth:300px;dialogHeight:250px;help:0;status:0;scroll:0;center:1");  &nbs...

how to accessing values and set values for a controls that is inside a datagrid
hi this is chandra mohan working as software engineer . here i am having problem with accessing valuse and setting values for controls inside a datagrid. actually i am having datagrid and in this grid i am having item templates of one dropdwon list and text box. i having one Reset link buttion out side the grid(that is in the form) by clicking this Reset Link buttion it should invokes the javascript function and in that function it should set all textboxes of datagrid to  .. txtActionVal.readOnly = true;   txtActionVal.Value ="";and dropdownlist to  dropdownlist...

Setting the Parameter Value to the Property Value of a Web Control
I want to filter my DetailsView with a declarative parameter. In my case, I am setting the SqlDataSource's parameter values based on the value of 2 TextBox controls on the page. I have a SP that does a SELECT based on 1 of the parameters passed in (either an ID or phone number). Param Name          Value MemberID          TextBox1.Text Phone               TextBox2.Text I want to assign a default value of 'null' for b...

Web resources about - Set TextBox text value to value from DataList Control - asp.net.presentation-controls

Email Domain Datalist Helper
What if someone signs up for your web app and they type in their email address as susan_smith@gmaoil.com? They don't notice, they never get their ...

South-west Marine Reserves Network - Resources
[toc on_off::hide=0 on_off::automatic=0 on_off::min_limit=5 box::title=Contents box::minlevel=2 box::maxlevel=2 box::hide_show=1 box::collapsed=1 ...

HTML5无障碍支持解决方案
工作正在进行中:实例解决方案 返回 表的图例 & 说明: “不支持" - 意味着如果提供有建设性意义的变通方案仍不能被浏览器支持。 “部分支持” - 意味着建设性意义的变通方案在浏览器中提供一些无障碍支持。 “没实现” - 意味着新特性在浏览器中仍然没有实现。 “支持” - means ...

銆婄函鐪熺殑骞翠唬銆嬬1闆哶楂樻竻鍦ㄧ嚎瑙傜湅_鏂版氮澶х墖_鏂版氮缃?/title>
... 鏂扮櫧鍙戦瓟濂充紶 鏄庢湞澶╁惎鍥涘勾锛屽箍鍏冨湴鍖鸿繛骞撮ゥ鑽?.. 娓╁窞涓€瀹朵汉 銆婃俯宸炰竴瀹朵汉銆嬩互涓€鎴锋櫘閫氫汉瀹剁殑... 闃垮浣块亾浼?/a> 銆婇樋濞樹娇閬撲紶銆嬩互鏈濋矞鏃朵唬涓鸿儗鏅?.. 鐑棬瑙嗛 姝e湪鍔犺浇...璇风◢绛墌 ${++dataList_index} ...

Adactio: Journal
The thoughts and ramblings of Jeremy Keith, a web developer living in Brighton in southern England.

datalist experiment
demo implementation of datalist element

Issues for pfeldman - Code Review
Keyboard Shortcuts File u : up to issue m : publish + mail comments M : edit review message j / k : jump to file after / before current file ...

Google’s new Chrome Beta 24 is 26% faster than last year’s browser
... the Octane Javascript benchmark. For developers, there are tons of new features in Chrome Beta 24 including new un-prefixed APIs, MathML, datalist ...

Accessible Mozilla: Firefox 24
Alex's blog Wednesday, July 10, 2013 Here's a list of Firefox 24 (currently Aurora ) improvements for assistive technology. ARIA We supported ...

Google Chrome 24 Released, Claims 26% Speed Improvement
Google today released a new version of its browser. On the Octane benchmark, this version is claimed to have 26% speed improvement over the last ...

Resources last updated: 12/15/2015 10:16:36 PM