A few questions regarding web based c#programming with visual studio 2010 and mysql
I'm making a web based inventory database that is connected to mysql, and I currently have a purchase order(PO) page for incoming stocks, delivery receipt(DR) page for outgoing stocks and a stock list page.
In the PO page is a grid view of my PO table connected to mysql with edit and delete enabled and the edit is linked to a separate page. Same goes with the DR page. Stock page has a grid view of Stock table connected to mysql with only edit enabled.
I have a separate add new page 开发者_如何学JAVAand edit page for PO and DR. Both add and edit pages have details view in them. Here are my questions.
1. How do I automatically insert records that are inserted in the add page using details view for both PO and DR to Stock table. My stock table looks like this:
Stock_ID | Date | PO_ID | DR_ID | Product_ID | Stock_In | Stock_Out | Stock_Balance |
What I want to happen is that when I enter either a new DR or PO, it'll go to the stock table automatically as well as their respective tables and the stock balance will adjust automatically.
2. In my details view of add new PO, I edited the details view so that when you choose a supplier and product you get to choose from a drop down list that is connected to their respective table, how do I limit what product the user can choose in regards to the supplier he /she chooses. Let's say that I choose supplier 1 and the products he supplies are products 1 and 2. What I want to happen is that when I choose supplier 1 the products that I can choose are limited to products 1 and 2.
This is the link to my AddPO source code
http://pastebin.com/download.php?i=5AaqHSc4
This is the link to my AddPO.cs source code
http://pastebin.com/download.php?i=Mz8GdLfx
Edit
The
InsertCommand
should be fired when aLinkButton
withCommandName="Insert"
is clicked, which you have at the bottom of the form. You can try querying any error messages during theItemInserted
event usingDetailsViewInsertedEventArgs.ExceptionHandled
to check if there was an unhandled exception, andDetailsViewInsertedEventArgs .Exception
to get the details of that exception. Does it work if you remove all of your logic you have placed in theItemInserting
event?Your
SqlDataSource
for the productsDropDown
should have a parameter ofSupplierId
, and yourSelectCommand
should filter based on that parameter.
Example code for SqlDataSource
:
<asp:SqlDataSource ID="SqlDataSource1"
SelectCommand="Select * from Products Where SupplierId=@SupplierId">
<SelectParameters>
<asp:Parameter Name="SupplierId" />
</SelectParameters>
</asp:SqlDataSource>
Example binding code (replace with correct control id's):
protected void SqlDataSource1_Selecting(
object sender, SqlDataSourceSelectingEventArgs e)
{
DropDown SupplierDropDown =
MyDetailsView.FindControl("SupplierDropDown") as DropDown;
e.Arguments["SupplierId"] = SupplierDropDown.SelectedValue;
}
Old
If your data is connected to a
DataSource
control, set theInsertStatement
orOnInsert
event to the appropriate code to handle inserting according to your spec. If you're binding theDetailsView
programmatically, then you will need to handle theItemInserting
event of the DetailsView, or use custom logic in your submit button. See http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.detailsview.iteminserting.aspx for more information.Use a
ControlParameter
on your data source of the productsDropDown
, tied the selected value of the SupplierDropDown
. Then setAutoPostBack=True
on the suppliersDropDown
, so any time a selection is made, the products list is updated accordingly.
精彩评论