Showing posts with label page_load. Show all posts
Showing posts with label page_load. Show all posts

Monday, March 26, 2012

populate detailview from code behind

i took it down to the basic level and still get an error -- Object reference not set to an instance of an object.

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load

If DetailsView1.CurrentMode = DetailsViewMode.EditThen

CType(Me.DetailsView1.FindControl("textbox1"), TextBox).Text ="here"

EndIf

EndSub

<

asp:DetailsViewID="DetailsView1"

runat="server"

DefaultMode="Edit">

<Fields>

<asp:TemplateFieldHeaderText="Ticket Number">

<EditItemTemplate>

<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>

</EditItemTemplate>

</asp:TemplateField>

</Fields>

</asp:DetailsView>

for all data control when you want to findcontrol in the row you should define which row you need to find the control therefore for the code you gave is not valid. it is becaus you are finding the control within the detailview list such as footer, header and other and not for the control in the row.

so may be you try thisCType(Me.DetailsView1.Rows.Item(index of the field).FindControl("textbox1"), TextBox).Text ="here"

I am not sure the code I given to you work or not but i am sure that it is the problem that i mention at above.

its the only thing in the detialview

CType(Me.DetailsView1.Rows.Item(0).FindControl("textbox1"), TextBox).Text = "here"

error i get -- Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index


oh yeah i have found the solution already

DetailsView1.Rows.Item(DetailsView1.PageIndex).FindControl(

"textbox1")

for get to tell you the item index need to be the pageindex. giving you the wrong example


same error

built another project -- this works fine in the page load -- when i move it to my user control in my main project it screws up

CType(Me.Details1.Rows.Item(0).FindControl("drop1"), DropDownList).SelectedValue = 5


tpiazza:

same error

built another project -- this works fine in the page load -- when i move it to my user control in my main project it screws up

CType(Me.Details1.Rows.Item(0).FindControl("drop1"), DropDownList).SelectedValue = 5

did you change the item index from 0 to details.pageindex?

CType(Me.Details1.Rows.Item(0).FindControl("drop1"), DropDownList).SelectedValue = 5

to

CType(Me.Details1.Rows.Item(Details1.PageIndex).FindControl("drop1"), DropDownList).SelectedValue = 5


Hello,

Look at these samples, especially "DetailsView Editing". They provide much codes and sample to follow.

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/detailsview.aspx

HTH

Wednesday, March 21, 2012

Populate Textboxes?

I am trying to populate a textbox with a random number and for the life of me I cant get the textbox to populate... any help?

Sub Page_Load()

Dim oRandom As New Random()
Dim iNum As Integer
iNum = oRandom.Next(1, 100000)

textbox1.text = iNum

end sub

I run the page and the textbox is still blank.Is the textbox standalone in the page, or is it nested in a formview?

Can you put anything in the textbox, i.e. textbox.text = "something"
no its not letting me put textbox1.text ="anything" ... I do have it between Form tags...

Im lost
Is it supposed to populate on page load? If so do you have te call inside an if not isportback...
yea I would like for it to populate on the page load
In that case, on the page load sub, add the following:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not IsPostBack Then
'Put all your page load stuff in here including the textbox piece
Dim oRandom As New Random()
Dim iNum As Integer
iNum = oRandom.Next(1, 100000)

textbox1.text = iNum

End If

End Sub
bah Im an idiot... lol... thanks...

Anjari

Populating a dropdown box

Hi all,

I have populated one dropdown menu using data from a database using the following code

Sub Page_Load (seander as Object, e as EventArgs) Year.DataSource = GetYear() Year.DataBind()End Sub Function GetYear() As System.Data.SqlClient.SqlDataReader Dim connectionString As String = "server='localhost'; user id='sa'; password='eoyson'; Database='PupilRoll'" Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionString) Dim queryString As String = "SELECT [Years].* FROM [Years]" Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection) sqlConnection.Open Dim dataReader As System.Data.SqlClient.SqlDataReader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection) Return dataReader End Function
I am now trying to populate another dropdown list depending on the information selected from the previous dropdown list.
Cheers!

Try the tutorial right on this site:

Master Detail Filtering with Two Dropdownlists

Friday, March 16, 2012

Populating DataList control

I have a datalist control on a web page and I am trying
to populate it through the page_load event.
The name of the control on the web page is "MyList".
I had code behind a button click to populate it and that
worked. Now that I've moved the code to the page_load
event it is not working. I suspect that "MyList" on the
page doesn't know about "MyList" in the page_load code
but I don't know how to connect the two. Any help would
be appreciated.
Here is the code
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
Dim MyList As DataList
MyConnection = New SqlConnection
(" server=x2;database=Orders;Trusted_Connec
tion=yes")
MyCommand = New SqlDataAdapter("select
ReferenceNO, Loc from Request", MyConnection)
DS = New DataSet
MyCommand.Fill(DS, "Request")
MyList = New DataList
MyList.DataSource = DS.Tables
("Request").DefaultView
MyList.DataBind()
.Hi, Jerry
From your code, I guess you are dynamically generating datalist.
However, I don't see any code to add the datalist to the page.
You need to add:
Page.Controls.Add(MyList)
Bin Song, MCP
Hi Bin,
I had added the DataList control from the toolbox. My
problem was that I had failed to add the
<%# DataBinder.Eval(Container.DataItem, "ReferenceNO") %>
inside the <td> tags in the control.
Thanks,
Jerry

>--Original Message--
>Hi, Jerry
>From your code, I guess you are dynamically generating
datalist.
>However, I don't see any code to add the datalist to the
page.
>You need to add:
>Page.Controls.Add(MyList)
>Bin Song, MCP
>.
>
So your problem solved or not?
Yes. Problem solved. Thanks.
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!

Populating DataList control

I have a datalist control on a web page and I am trying
to populate it through the page_load event.

The name of the control on the web page is "MyList".

I had code behind a button click to populate it and that
worked. Now that I've moved the code to the page_load
event it is not working. I suspect that "MyList" on the
page doesn't know about "MyList" in the page_load code
but I don't know how to connect the two. Any help would
be appreciated.

Here is the code

Dim DS As DataSet
Dim MyConnection As SqlConnection

Dim MyCommand As SqlDataAdapter
Dim MyList As DataList

MyConnection = New SqlConnection
("server=x2;database=Orders;Trusted_Connection=yes")
MyCommand = New SqlDataAdapter("select
ReferenceNO, Loc from Request", MyConnection)

DS = New DataSet
MyCommand.Fill(DS, "Request")

MyList = New DataList
MyList.DataSource = DS.Tables
("Request").DefaultView

MyList.DataBind()
..Hi Bin,

I had added the DataList control from the toolbox. My
problem was that I had failed to add the

<%# DataBinder.Eval(Container.DataItem, "ReferenceNO") %
inside the <td> tags in the control.

Thanks,

Jerry

>--Original Message--
>Hi, Jerry
>From your code, I guess you are dynamically generating
datalist.
>However, I don't see any code to add the datalist to the
page.
>You need to add:
>Page.Controls.Add(MyList)
>Bin Song, MCP
>.
So your problem solved or not?
Yes. Problem solved. Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!