How To Add (preload) default information into an ASP:LISTVIEW's Insert Textbox

by rlynch February 16, 2010 00:40

Assuming you have a datalist called "listview1" and a bound field called "DateShipped", the insert template will have a textbox called "DateShippedTextBox".

Top prepopulate it with a value all you need to do is add some code in the form's load event or some other event (Not necessarly the listbox's loading events) and modify the Text property. - THe key is using the "FindControl" method of the listviews insertitem collection.

** Update **

For this to work porperly you need to place the code in the databound event of the listview control 

e.g.

C#

protected void listView1_DataBound(Object sender, System.EventArgs e){ 

TextBox tb;

tb = (TextBox)listView1.InsertItem.FindControl("OrderDateTextBox"); 

tb = (TextBox)listView1.DateTime.Today.ToShortDateString();

}

VB

protected Sub listView1__DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DataBound

dim tb as TextBox= CType(listview1.InsertItem.FindControl("DateShippedTextBox") ,TextBox)

tb.Text =Now().ToShortDateString()

end Sub

Currently rated 4.5 by 2 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

asp.net | asp:listview | dot.net application development

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen | Modified by Mooglegiant

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar