Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Data List Insert new problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ed Dror - 03 Mar 2008 21:00 GMT
Hi there,

I'm using Wisual Studio 2005 Pro with SQL server 2005 Dev on XP SP2

I have two tables
Generic Item table (GN_ID) PK
Color Table (Color_ID) PK and GN_ID FK
very simple one to many relationship (one Generic Item can have many colors)

I created a Dropdown list that select items from Generic Item table
Then I created a Datalist control based on the GN_ID in the dropdown list
with Edit and new Button
Until here everything was very simple and work just fine

when I pick a Generic Item the data list show all color that belong to this
item.

Now when you click on new button the GN_ID field become empty and I want to
preserve that GN_ID
I don't want the user to enter the GN_ID every time they enter a new color
based on GN_ID from the Generic Table

Is there any way to read the GN_ID from cache?
Or create a trigger? if so how

Thanks,
Ed Dror
Steven Cheng - 04 Mar 2008 02:51 GMT
Hi Ed,

Based on my understanding, you have the following controls on the page to
display some one-many datas:

** a dropdown that display the main records
** a datalist that display detailed info of main record(selected in
dropdown)

And your question here is how to make the textbox contains initial value(of
the PK of current main record) when user perform inserting(for child
colors), correct?

I'd suggest you poste a simplified aspx page template and some brief
description of how the controls will work together at runtime so as for me
to understand it more clearly.  So far, I think the init value for
textbox(for inserting) can be got from two place:

1. Is the dropdownlist (since datalist's displaying record also come from
dropdownlist selection)

2. Is the DataList

If this is true, there are also multiple means:

1. Add Event handler for the textbox(for inserting) and it will query the
current selected dropdownlist item and retrieve the PK info from it

2. You can store the info into DataList during databinding and then let the
Textbox retrieve the value from the control(maybe a html hidden field)
later (like in #1)

If this is not quite clear, you can give me some html snippet and I'll try
providing some ideas depend on them.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================
   

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "Ed Dror" <edd@andrewlauren.com>
>Subject: Data List Insert new problem
[quoted text clipped - 27 lines]
>Thanks,
>Ed Dror
Ed Dror - 04 Mar 2008 21:28 GMT
Steven,

Catalog_GN table
GN_ID - PK
Brand
Model

this table point to Dropdown List GN_ID Data value field
and Data text field point to (Brand + Model)

Color
ColorID PK
ColorName
GN_ID FK reference to Catalog_GN table

One to Many relationship

This point to detail view control (select * from color where GN_Id = @GN_Id)
where the @GN_Id is the drop down control GN_ID

Now when I'm selecting let say GN_ID 35 in the the drop down
The DetailsView control show ColorID = 40 with 3 colors (that belong to the
GN_ID)
The GN_ID show 35

is very simple and work fine

Now when you add a new Color the Details view control open a blank fields
(except for the ColorID)

My question is there any way to preserve the GN_ID (35) when you click on
New color?
Like on index change me.DetailsView1.FindControl("GN_ID") =
me.Dropdownlist1.Text
or somthing like that to save the user entry that can cause mistake
When you click on edit for example nothing change

Thanks,
Ed Dror

> Hi Ed,
>
[quoted text clipped - 97 lines]
>>Thanks,
>>Ed Dror
Steven Cheng - 05 Mar 2008 03:41 GMT
Thanks for your reply Ed,

So for the control display the color lists you selected from database, is
it a DataList or DetailsView control? It would be hard for me to give you
some detailed code snippet without knowing the exact control you used,
that's why I ask you give me some aspx template or snippet that will make
it much easier to understand(database schema is not  that important here
since what we want to do is just get a value which is databound to display
in another control and the control structure is the most important thing
here).

I assume that your insert template( those controls that help you insert a
new record of Color) contains a Textbox to let user input Color ID, then,
you can just use the following code in Textbox's "preRender" event to
assign it the value from DropDownlist:

<<<<<<<<<<<<<<<<<<
Protected Sub TextBox1_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.PreRender
       Dim ddl As DropDownList = Page.Form.FindControl("DropDownList1")
       Dim txt As TextBox = sender

       txt.Text = ddl.SelectedValue

   End Sub

#again, here I assume that the DropDownlist is at top level of the page and
I use Form.FindControl to locate it. This may vary depend on the control
hierarchy

Also, as you mentioned, you may also do the updating in DropDownList's
selected index change event to refresh the TextBox's value.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "Ed Dror" <edd@andrewlauren.com>
>References: <#$p5#EXfIHA.6136@TK2MSFTNGP03.phx.gbl>
<xb0g8KafIHA.6844@TK2MSFTNGHUB02.phx.gbl>
>Subject: Re: Data List Insert new problem
>Date: Tue, 4 Mar 2008 13:28:02 -0800
[quoted text clipped - 85 lines]
>>
>> Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
>> ications.
>>
[quoted text clipped - 50 lines]
>>>Thanks,
>>>Ed Dror
Ed Dror - 05 Mar 2008 19:09 GMT
Steven,

I try this solution but it dosen't seems to work so I changed the dropdown
to GridView with the folowing code
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles GridView1.SelectedIndexChanged

txtGNID.Text = Me.GridView1.SelectedRow.Cells(1).Text

End Sub

Then I created a form with submit botton that call Stored Proc
usp_InsertColor and it works

Thanks,

Ed Dror

> Thanks for your reply Ed,
>
[quoted text clipped - 203 lines]
>>>>Thanks,
>>>>Ed Dror
Steven Cheng - 06 Mar 2008 02:25 GMT
Hi Ed,

Thanks for your reply.

so your current solution is using  GridView's SelectedIndexChanged event to
synchronize the Textbox,  I think that's also a good idea.

Thanks for sharing this with us.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
   

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "Ed Dror" <edd@andrewlauren.com>
>Subject: Re: Data List Insert new problem
>Date: Wed, 5 Mar 2008 11:09:45 -0800

>Steven,
>
[quoted text clipped - 157 lines]
>>>>
>>>> Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
>>>> ications.
>>>>
[quoted text clipped - 58 lines]
>>>>>Thanks,
>>>>>Ed Dror

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.