抱歉,我知道很多代码
<%@ Register Assembly =“AjaxControlToolkit”Namespace =“AjaxControlToolkit”TagPrefix =“asp”%>
<asp:GridView ID="GridView1" runat="server" DataSourceID="partsUsed" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" DataKeyNames="parts_used_id">
<Columns>
<asp:ButtonField Text="Button" Visible="False" />
<asp:BoundField DataField="parts_used_id" HeaderText="parts_used_id" InsertVisible="False"
ReadOnly="True" SortExpression="parts_used_id" Visible="False" />
<asp:BoundField DataField="tasks" HeaderText="Work Order" ReadOnly="True"
SortExpression="tasks" />
<asp:TemplateField HeaderText="Part" SortExpression="Part">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="partsList" DataTextField="Part"
DataValueField="part_id" SelectedValue='<%# Bind("part_id") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Part") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="part_id" HeaderText="part_id" SortExpression="part_id"
Visible="False" />
<asp:BoundField DataField="quantity" HeaderText="Quantity" SortExpression="quantity" />
<asp:BoundField DataField="cost" DataFormatString="{0:C}" HeaderText="Price Per" SortExpression="cost" />
<asp:BoundField DataField="full_name" HeaderText="Entered By"
SortExpression="full_name" ReadOnly="True" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbDelete" runat="server" CommandName="Delete">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<EmptyDataTemplate>
No Parts Logged<br />
</EmptyDataTemplate>
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="Gainsboro" />
</asp:GridView>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" Width="250px" />
<EditItemTemplate>
<asp:HiddenField ID="hfWOId" runat="server" Value='<%# Eval("wo_id") %>' />
<asp:HiddenField ID="hfDept" runat="server"
Value='<%# Eval("machine_type_id") %>' Visible = "false" />
<asp:HiddenField ID="hfMachine" runat="server"
Value='<%# Eval("machine_id") %>' />
<asp:HiddenField ID="hfReason" runat="server"
Value='<%# Eval("reason_id") %>' />
<asp:SqlDataSource ID="sqlDepartments" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [type_description], [machine_type_id] FROM [list_machine_types] ORDER BY [type_description]">
</asp:SqlDataSource>
<asp:DropDownList ID="ddlDepartment" runat="server" DataSourceID="sqlDepartments" Visible = "false"
DataTextField="type_description" DataValueField="machine_type_id" SelectedValue='<%# Bind("machine_type_id") %>'
AutoPostBack="True"
onselectedindexchanged="ddlDepartment_SelectedIndexChanged">
</asp:DropDownList>
<br />
<asp:Label ID="Label30" runat="server" Font-Bold="true" Text="Machine Number:" Visible = "false"></asp:Label>
<asp:DropDownList ID="ddlMachine" runat="server" Visible = "false">
</asp:DropDownList>
<br />
<asp:Label ID="Label10" runat="server" Font-Bold="true" Text="Serial Number:" Visible = "false"></asp:Label><asp:Label
ID="lblSerialNum" runat="server" Text='<% #Eval("serial_number") %>' Visible = "false"></asp:Label><asp:Label
ID="Label50" runat="server" Font-Bold="true" Text="Machine Status:" Visible = "false"></asp:Label>
<asp:DropDownList ID="ddlMachineStatus" runat="server" DataSourceID="machineStatus" Visible = "false"
DataTextField="machine_status_desc" DataValueField="machine_status_id" SelectedValue='<%# Bind("machine_status_id") %>'>
</asp:DropDownList>
<br />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Font-Bold="True" Text="Department:"></asp:Label>
<asp:Label ID="lblReason" runat="server" Text='<%# Eval("reason_desc") %>'></asp:Label> <br />
<asp:Label ID="Label29" runat="server" Text="Issued To:" Font-Bold="true"></asp:Label> 
<asp:Label ID="lblIssuedTo" runat="server" Text='<% #Eval("issue_to_desc") %>'></asp:Label><br />
<asp:Label ID="Label39" runat="server" Text="Description:" Font-Bold="true"></asp:Label><br />
<asp:Label ID="lblDescription" runat="server" Text='<% #Eval("work_order_desc") %>'></asp:Label><br />
<asp:Label ID="lblMaterialLabel" runat="server" Text="Material:" Font-Bold="true" Visible="false"></asp:Label> 
<asp:Label ID="lblMaterial" runat="server" Text='<% #Eval("material_nbr_MATNR") %>' Visible="false"></asp:Label><br />
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" Width="250px" Wrap="True" />
<EditItemTemplate>
<asp:Label ID="Label2" runat="server" Font-Bold="True" Text="Department:"></asp:Label>
<asp:DropDownList
ID="ddlReason" runat="server">
</asp:DropDownList>
<asp:Label ID="Label29" runat="server" Font-Bold="true" Text="Issued To:"></asp:Label>
<asp:DropDownList ID="ddlIssuedTo" runat="server" DataSourceID="issuedTo" DataTextField="issue_to_desc"
DataValueField="issued_to" SelectedValue='<%# Bind("issued_to") %>'>
</asp:DropDownList>
<br />
<asp:Label ID="Label39" runat="server" Font-Bold="true" Text="Description:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Height="54px" Text='<%# Bind("work_order_desc") %>'
Width="273px" TextMode="MultiLine"></asp:TextBox><br />
<asp:Label ID="lblMaterialLabel" runat="server" Text="Material:" Font-Bold="true" Visible="false"></asp:Label> 
<asp:DropDownList ID="ddlMaterial" runat="server" AppendDataBoundItems="True" Visible="false"
DataSourceID="sqlMaterials" DataTextField="material_nbr_MATNR"
DataValueField="material_nbr_MATNR"
SelectedValue='<%# Bind("material_nbr_MATNR") %>'>
<asp:ListItem Enabled="true" Text="None" Value="None" />
</asp:DropDownList>
<br />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label28" runat="server" Text="Requested By:" Font-Bold="true"></asp:Label> 
<asp:Label ID="lblRequestedBy" runat="server" Text='<% #Eval("requested_by") %>'></asp:Label><br />
<asp:Label ID="Label48" runat="server" Text="Requested On:" Font-Bold="true"></asp:Label> 
<asp:Label ID="lblRequestedOn" runat="server" Text='<% #Eval("requested_on", "{0:d}") %>'></asp:Label><br />
<asp:Label ID="Label78" runat="server" Text="Required By:" Font-Bold="true"></asp:Label> 
<asp:Label ID="lblRequiredBy" runat="server" Text='<% #Eval("required_by", "{0:d}") %>'></asp:Label>
<br />
<asp:Label ID="Label77" runat="server" Text="WO Status:" Font-Bold="true"></asp:Label>
<asp:LinkButton ID="lbWOStatus" runat="server" Text='<% #Eval("status_description") %>'
CommandName="ChangeWOStatus"></asp:LinkButton>
<asp:DropDownList ID="ddlWOStatus" Visible="False" runat="server" AutoPostBack="True"
DataSourceID="woStatus" DataTextField="status_description" DataValueField="status_id"
OnSelectedIndexChanged="updateWOStatus" SelectedValue='<%# Bind("wo_status_id") %>'>
</asp:DropDownList>
<asp:LinkButton ID="lbCancel" runat="server" CommandName="CancelStatusChange" Visible="False">Cancel</asp:LinkButton><br />
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" Width="250px" />
<EditItemTemplate>
<asp:Label ID="Label28" runat="server" Font-Bold="true" Text="Requested By:"></asp:Label>
<asp:Label ID="lblRequestedBy" runat="server" Text='<% #Eval("requested_by") %>'></asp:Label><br />
<asp:Label ID="Label48" runat="server" Font-Bold="true" Text="Requested On:"></asp:Label>
<asp:Label ID="lblRequestedOn" runat="server" Text='<% #Eval("requested_on", "{0:d}") %>'></asp:Label><br />
<asp:Label ID="Label78" runat="server" Font-Bold="true" Text="Required By:"></asp:Label>
<asp:TextBox ID="txtRequiredBy" runat="server" Text='<%# Bind("required_by") %>'
Width="100px"></asp:TextBox><br />
<asp:Label ID="Label77" runat="server" Font-Bold="true" Text="WO Status:"></asp:Label>
<asp:Label ID="lblWOStatus" runat="server" Text='<%# Eval("status_description") %>'></asp:Label>
<br />
<asp:CalendarExtender ID="CalendarExtender1" runat="server" Enabled="True" SelectedDate='<%# Eval("required_by") %>'
TargetControlID="txtRequiredBy">
</asp:CalendarExtender>
<asp:LinkButton ID="lbWOStatus" runat="server" CommandName="ChangeWOStatus" Text='<% #Eval("status_description") %>'
Visible="False"></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnApprove" runat="server" Text="Approve" BackColor="#00C000" Font-Size="Medium"
Height="40px" Width="70px" CommandName="Approve" />
<br />
<asp:Button ID="btnDeny" runat="server" Text="Deny" BackColor="#C00000" Font-Size="Medium"
ForeColor="Black" Height="40px" Width="70px" CommandName="Deny" />
<br />
<asp:Label ID="lblPending" runat="server" Text="Pending Approval" Visible="False"></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:HiddenField ID="hfPriority" runat="server" Value='<%# Eval("priority", "{0:N}") %>' />
<asp:HiddenField ID="hfApprovalStatus" runat="server" Value='<% #Eval("approval_status_id") %>' />
<asp:ImageButton ID="btnTopPriority" runat="server" CommandName="MakeTopPriority"
ImageUrl="~/App_Themes/Images/priority.png" /><br />
<asp:ImageButton ID="btnUp" runat="server" Height="40px" ImageUrl="~/App_Themes/Images/upArrow.png"
Width="40px" CommandName="Up" /><br />
<asp:ImageButton ID="btnDown" runat="server" Height="40px" ImageUrl="~/App_Themes/Images/downArrow.png"
Width="40px" CommandName="Down" /><br />
<asp:LinkButton ID="lbChangePriority" runat="server" CommandArgument='<%# Eval("wo_id") %>'
CommandName="ChangePriority">Notify New Priority</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbDelete" runat="server" CommandArgument='<%# Eval("wo_id") %>'
CommandName="DeleteWO">Delete</asp:LinkButton>
<br />
<br />
<asp:LinkButton ID="lbMoveToProjects" runat="server" CommandArgument='<%# Eval("wo_id") %>'
CommandName="MoveToProjects" OnClientClick="javascript:return confirm('Are you sure you want to move this to projects?')" Visible="false">Move To Projects</asp:LinkButton>
<br />
<br />
<asp:LinkButton ID="lbEngineeringChange" runat="server" CommandArgument='<%# Eval("wo_id") %>' CommandName="EngineeringChange" Visible="false">Push For Engineering Change</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbPrintISO" runat="server" CommandName="PrintISO">Print ISO</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
No work orders.<br />
</EmptyDataTemplate>
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="Gainsboro" />
</asp:GridView>
</center>
<br />'
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<center>
<asp:SqlDataSource ID="workOrders" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="sp_WorkOrders"
UpdateCommand="UPDATE fact_work_orders SET machine_id = @machine_id, reason_id = @reason_id, machine_status_id = @machine_status_id, issued_to = @issued_to, work_order_desc = @work_order_desc, material_nbr_MATNR = @material_nbr_MATNR, required_by = @required_by WHERE wo_id = @wo_id"
SelectCommandType="StoredProcedure">
<UpdateParameters>
<asp:Parameter Name="machine_id" />
<asp:Parameter Name="reason_id" />
<asp:Parameter Name="machine_status_id" />
<asp:Parameter Name="issued_to" />
<asp:Parameter Name="work_order_desc" />
<asp:Parameter Name="material_nbr_MATNR" />
<asp:Parameter Name="required_by" />
<asp:Parameter Name="wo_id" Type="Int16" />
</UpdateParameters>
<SelectParameters>
<asp:QueryStringParameter Name="issuedTo" QueryStringField="issuedTo" DefaultValue="0" />
<asp:QueryStringParameter Name="woStatus" QueryStringField="woStatus" Type="String"
DefaultValue="%" />
<asp:SessionParameter DefaultValue="0" Name="level" SessionField="level" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="woStatus" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [status_description], [status_id] FROM [list_wo_status] WHERE ([status_id] <> @status_id)">
<SelectParameters>
<asp:Parameter DefaultValue="3" Name="status_id" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="machineStatus" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [machine_status_desc], [machine_status_id] FROM [list_machine_status]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="departments" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [type_description], [machine_type_id] FROM [list_machine_types]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="issuedTo" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [issued_to], [issue_to_desc] FROM [list_issued_to]"></asp:SqlDataSource>
<asp:SqlDataSource ID="sqlMaterials" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [material_nbr_MATNR] FROM [vdim_materials] ORDER BY [material_nbr_MATNR]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="partsUsed" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
DeleteCommand="DELETE FROM [fact_parts_used] WHERE [parts_used_id] = @parts_used_id"
InsertCommand="INSERT INTO [fact_parts_used] ([wo_id], [part_id], [quantity]) VALUES (@wo_id, @part_id, @quantity)"
SelectCommand="SELECT * FROM
(SELECT parts_used_id,dim_users。[user_name],full_name, wo_id作为任务, fact_parts_used.part_id,dim_parts.part_number +''+ dim_parts.part_desc作为零件,数量,成本 FROM fact_parts_used INNER JOIN dim_users ON dim_users。[user_id] = fact_parts_used。[user_id] INNER JOIN dim_parts ON dim_parts.part_id = fact_parts_used.part_id ) 一个 WHERE任务不为空且任务=任务“
UpdateCommand="UPDATE [fact_parts_used] SET [part_id] = @part_id, [quantity] = @quantity, cost = @cost WHERE [parts_used_id] = @parts_used_id"
>
<SelectParameters>
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="parts_used_id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="part_id" Type="Int32" />
<asp:Parameter Name="quantity" Type="Int32" />
<asp:Parameter Name="parts_used_id" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="wo_id" Type="Int32" />
<asp:Parameter Name="part_id" Type="Int32" />
<asp:Parameter Name="quantity" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
</center>
我需要知道的是如何获得'&lt;%#Eval(“wo_id”)%&gt;'到partused sql datasource底部的select语句中。有没有办法可以将wo_id值保存到全局变量中,或者有一些方法可以将它传递给嵌套的gridview。它在gridview中基本上做的是为每个工单生成一个表,然后在嵌套gridview中生成每个工单的零件列表。问题是,如果不能将gridviews当前的工单ID传递到嵌套的gridview中,它所做的就是打印出每一个部分。
答案 0 :(得分:1)
在内部gridview上方,模板内添加一个隐藏字段: 更改partsUsed sqldatasource的SelectCommand:
编辑:同时在GridView2中移动sqldatasource。您的标记应如下所示:
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("wo_id") %>'/>
<asp:SqlDataSource ID="partsUsed" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
DeleteCommand="DELETE FROM [fact_parts_used] WHERE [parts_used_id] = @parts_used_id"
InsertCommand="INSERT INTO [fact_parts_used] ([wo_id], [part_id], [quantity]) VALUES (@wo_id, @part_id, @quantity)"
SelectCommand="SELECT * FROM
(SELECT parts_used_id, dim_users.[user_name], full_name,
wo_id as tasks,
fact_parts_used.part_id, dim_parts.part_number+' '+dim_parts.part_desc as Part, quantity, cost
FROM fact_parts_used
INNER JOIN dim_users ON dim_users.[user_id] = fact_parts_used.[user_id]
INNER JOIN dim_parts ON dim_parts.part_id = fact_parts_used.part_id
) a
WHERE tasks is not null AND (tasks = @wo_id) "
UpdateCommand="UPDATE [fact_parts_used] SET [part_id] = @part_id, [quantity] = @quantity, cost = @cost WHERE [parts_used_id] = @parts_used_id"
>
<SelectParameters>
<asp:ControlParameter ControlID="HiddenField1" Name="wo_id" PropertyName="Value" Type="Int32" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="parts_used_id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="part_id" Type="Int32" />
<asp:Parameter Name="quantity" Type="Int32" />
<asp:Parameter Name="parts_used_id" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="wo_id" Type="Int32" />
<asp:Parameter Name="part_id" Type="Int32" />
<asp:Parameter Name="quantity" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView2" runat="server" DataSourceID="partsUsed"