Showing posts with label basic. Show all posts
Showing posts with label basic. 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

Populating a DB from a DropDownList Control

Good afternoon. I'm in the midst of writing up a pretty "basic" web
form and having some difficulties. I'm completely open for
suggestions. I'm using VS.net 2003, and what iwould like to accomplish
is to have a form with two dropdown Boxes a button and a datagrid to
display what was selected from the drop downs. One of the drop downs
values can not be used more than once while the others can be repeated
as often as they like. Being that I'm a somewhat new developer I'm
finding even the easiest tasks to be difficult. The DropDownBoxes are
server controls that I pre-populated from in the aspx html. These
values will change very infrequently, so editing the aspx to add more
shouldn't be a problem. The problem that I'm having is that I can not
get any values to show in the Data Grid. These values must also be
stored in a DB that I created. I'm on what Data Controls I
would need, how to configure them. I have a SQLConnection control and
it is, to my belief able to connect to the DB. I have also read to
have a SQLCommand control and a SQLDataAdapter control. Any assistance
is greatly appreciated. Thanks, WillTry this.
Dim myConn as SqlConnection = New SqlConnection(Connection string)
Dim myDa as SqlDataAdapter = new SqlDataAdapter("Select query", myConn)
myConn.Open()
Dim myDs as DataSet = New DataSet
myDa.Fill(Ds, "All") '{populate Dataset with data
'Bind data to datagrid
datagrid1.DataSource = Ds
datagrid1.DataBind()
wcaruso welcome to the forum..
Try looking at this sample at:-
http://aspnet101.com/aspnet101/aspn...e.aspx?code=md2
It should guide you.
Also try seeing through quickstart at:-
http://asp.net/Tutorials/quickstart.aspx
Hope that helps
Patrick
<wcaruso@.gmail.com> wrote in message
news:1130962262.235096.310430@.g44g2000cwa.googlegroups.com...
> Good afternoon. I'm in the midst of writing up a pretty "basic" web
> form and having some difficulties. I'm completely open for
> suggestions. I'm using VS.net 2003, and what iwould like to accomplish
> is to have a form with two dropdown Boxes a button and a datagrid to
> display what was selected from the drop downs. One of the drop downs
> values can not be used more than once while the others can be repeated
> as often as they like. Being that I'm a somewhat new developer I'm
> finding even the easiest tasks to be difficult. The DropDownBoxes are
> server controls that I pre-populated from in the aspx html. These
> values will change very infrequently, so editing the aspx to add more
> shouldn't be a problem. The problem that I'm having is that I can not
> get any values to show in the Data Grid. These values must also be
> stored in a DB that I created. I'm on what Data Controls I
> would need, how to configure them. I have a SQLConnection control and
> it is, to my belief able to connect to the DB. I have also read to
> have a SQLCommand control and a SQLDataAdapter control. Any assistance
> is greatly appreciated. Thanks, Will
>

Populating a DB from a DropDownList Control

Good afternoon. I'm in the midst of writing up a pretty "basic" web
form and having some difficulties. I'm completely open for
suggestions. I'm using VS.net 2003, and what iwould like to accomplish
is to have a form with two dropdown Boxes a button and a datagrid to
display what was selected from the drop downs. One of the drop downs
values can not be used more than once while the others can be repeated
as often as they like. Being that I'm a somewhat new developer I'm
finding even the easiest tasks to be difficult. The DropDownBoxes are
server controls that I pre-populated from in the aspx html. These
values will change very infrequently, so editing the aspx to add more
shouldn't be a problem. The problem that I'm having is that I can not
get any values to show in the Data Grid. These values must also be
stored in a DB that I created. I'm confused on what Data Controls I
would need, how to configure them. I have a SQLConnection control and
it is, to my belief able to connect to the DB. I have also read to
have a SQLCommand control and a SQLDataAdapter control. Any assistance
is greatly appreciated. Thanks, WillTry this.

Dim myConn as SqlConnection = New SqlConnection(Connection string)
Dim myDa as SqlDataAdapter = new SqlDataAdapter("Select query", myConn)

myConn.Open()
Dim myDs as DataSet = New DataSet

myDa.Fill(Ds, "All") '{populate Dataset with data

'Bind data to datagrid
datagrid1.DataSource = Ds
datagrid1.DataBind()
wcaruso welcome to the forum..
Try looking at this sample at:-
http://aspnet101.com/aspnet101/aspn...e.aspx?code=md2
It should guide you.
Also try seeing through quickstart at:-
http://asp.net/Tutorials/quickstart.aspx
Hope that helps
Patrick

<wcaruso@.gmail.com> wrote in message
news:1130962262.235096.310430@.g44g2000cwa.googlegr oups.com...
> Good afternoon. I'm in the midst of writing up a pretty "basic" web
> form and having some difficulties. I'm completely open for
> suggestions. I'm using VS.net 2003, and what iwould like to accomplish
> is to have a form with two dropdown Boxes a button and a datagrid to
> display what was selected from the drop downs. One of the drop downs
> values can not be used more than once while the others can be repeated
> as often as they like. Being that I'm a somewhat new developer I'm
> finding even the easiest tasks to be difficult. The DropDownBoxes are
> server controls that I pre-populated from in the aspx html. These
> values will change very infrequently, so editing the aspx to add more
> shouldn't be a problem. The problem that I'm having is that I can not
> get any values to show in the Data Grid. These values must also be
> stored in a DB that I created. I'm confused on what Data Controls I
> would need, how to configure them. I have a SQLConnection control and
> it is, to my belief able to connect to the DB. I have also read to
> have a SQLCommand control and a SQLDataAdapter control. Any assistance
> is greatly appreciated. Thanks, Will

Friday, March 16, 2012

Populating a DropDownList with a Data Method Code Wizard

Please help... I am sure most of you guys know the answer to this basic question

I am using the Web Matrix ...Getting Started Manual and am to the

Using a Data Method Code Wizard to Populate a DropDownList.

The question is : When asked to Remove the Button1_Click event code...

How is this done? Do I remove the entire code?? And where is the event code?

Sub Button1_Click(sender As Object, e As EventArgs)
DataList1.DataSource = GetOrderDetails(CInt(TextBox1.Text))
DataList1.DataBind()
End SubIn WebMatrix, new events are automatically hooked up to event handlers declaratively. So, after creating a method that handles a Button webcontrol's OnClick event, you'll have something like this in your HTML view:


<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button>

In this example, the 'onclick' attribute's value identifies the name of the method that handles this control's Click event.

So, if you want to unhook an method from an event in Web Matrix, the simplest way to do this is to remove the corresponding event's attribute on that control's tag. What you do with the method's code after that is entirely up to you.

Hope this helps!
No..this did not help..but thanks anyway. Could you please go to the following URL and see what I mean.

http://www.asp.net/webmatrix/guidedtour/section4/ddlcodebuilder.aspx

I am 1/3 of the way through the tutorial and I like ASP.Net thus far.