Data List Insert new problem

E

Ed Dror

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
 
S

Steven Cheng

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.



--------------------
 
E

Ed Dror

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
 
S

Steven Cheng

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.




--------------------
 
E

Ed Dror

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
 
S

Steven Cheng

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" <[email protected]>
Subject: Re: Data List Insert new problem
Date: Wed, 5 Mar 2008 11:09:45 -0800
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top