详细信息视图插入和取消命令未从面板内部触发

时间:2015-08-20 20:28:11

标签: c# asp.net gridview ajaxcontroltoolkit detailsview

我正在处理工作订单管理Web应用程序.net 4.5 C#Requestor创建工作订单创建工作订单Supervisor可以查看所有工作订单,如何将一半的gridview数据留空,因为主管将审查上半部分,然后使用详细信息视图填写下半部分,以便所有工作都很好用户将详细信息输入到详细信息视图中单击提交(插入命令)并将数据添加到数据库并在gridview上刷新,仅当详细信息视图不在面板中时,新要求是在gridview上单击+图像按钮时将详细信息视图弹出为该特定行的模态,输入其他详细信息并提交他们想要此功能,因为想要在网页上显示的网格视图上有更多数据:

enter image description here

详细信息在ModalPopUpExtender中查看

TargetControlID="pnl1" PopupControlID="pnl1" ></asp:ModalPopupExtender>

<asp:HiddenField ID="HiddenField1" runat="server" />

<asp:Panel ID="pnl1" runat="server" Width="881px" Height="175px">
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True"
AutoGenerateRows="False" DataKeyNames="WorkOrderNum" BackColor="#39B1CC"
DataSourceID="SqlDataSource2" DefaultMode="Insert" Height="175px"
Width="881px" Font-Bold="True" ForeColor="White" PostBack = "True"
oniteminserted="DetailsView1_ItemInserted" OnItemCommand="DetailsView1_ItemCommand">
<Fields>
<asp:TemplateField HeaderText="WorkPerformed / PartsUsed"
SortExpression="column1">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("column1") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("column1") %>' Height="29px" Width="699px"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("column1") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Work Completed By " SortExpression="column2">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("column2") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("column2") %>' Height="29px" Width="699px"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("column2") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Maint. Supv. Approval" SortExpression="column3">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("column3") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("column3") %>' Height="29px" Width="699px"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("column3") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Q.C. Inspection By" SortExpression="column4">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("column4") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("column4") %>' Height="29px" Width="699px"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("column4") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Work_Comp_Date" SortExpression="Work_Comp_Date">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Work_Comp_Date") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Work_Comp_Date") %>' Height="29px" Width="699px"></asp:TextBox>

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Date format in DD/MM/YYYY" ValidationExpression = "^(0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])[-/.](19|20)\d\d$" ControlToValidate = "TextBox5"></asp:RegularExpressionValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("Work_Comp_Date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Supv_Approval_Date"
SortExpression="Supv_Approval_Date">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server"
Text='<%# Bind("Supv_Approval_Date") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox6" runat="server"
Text='<%# Bind("Supv_Approval_Date") %>' Height="29px" Width="699px"></asp:TextBox>

<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="Date format in DD/MM/YYYY" ValidationExpression = "^(0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])[-/.](19|20)\d\d$" ControlToValidate = "TextBox6"></asp:RegularExpressionValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("Supv_Approval_Date") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Maint. Supv. Approval Date"
SortExpression="column5">
<EditItemTemplate>
<asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("column5") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>

<asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("column5") %>' Height="29px" Width="699px"></asp:TextBox>

<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ErrorMessage="Date format in DD/MM/YYYY" ValidationExpression = "^(0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])[-/.](19|20)\d\d$" ControlToValidate = "TextBox9"></asp:RegularExpressionValidator>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label9" runat="server" Text='<%# Bind("column5") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Safety_Inspected_By"
SortExpression="Safety_Inspected_By">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server"
Text='<%# Bind("Safety_Inspected_By") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox7" runat="server"
Text='<%# Bind("Safety_Inspected_By") %>'  Height="29px" Width="699px" ></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("Safety_Inspected_By") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status" SortExpression="Status">
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("Status") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" Height="29px" Width="699px" DataTextField="Status" DataValueField = "Status" SelectedValue='<%# Bind("Status") %>'>
<asp:ListItem>New</asp:ListItem>
<asp:ListItem>Complete</asp:ListItem>
<asp:ListItem>Waiting For Approval</asp:ListItem>
<asp:ListItem>Denied</asp:ListItem>
<asp:ListItem>Cancel</asp:ListItem>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<EditItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="True"
CommandName="Update" Text="Submit" onclick="Button1_Click1" />
&nbsp;<asp:Button ID="Button2" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" OnClick="Button2_Click" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="True"
CommandName="Insert" onclick="Button1_Click" Text="Submit" />
&nbsp;<asp:Button ID="Button2" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit" />
&nbsp;<asp:Button ID="Button2" runat="server" CausesValidation="False"
CommandName="New" Text="New" />
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>

: &nbsp;
<asp:TextBox ID="TextBox10" runat="server" Height="25px"></asp:TextBox>
&nbsp;
</asp:Panel>

点击图片按钮时

 protected void ImageButton1_Click(object sender, ImageClickEventArgs e)

 {
 //DetailsView1.Visible = true;
   ImageButton imgbtn = (ImageButton)sender;
    GridViewRow GridView1 = (GridViewRow)imgbtn.NamingContainer;
    string workordernum = GridView1.Cells[3].Text;
    TextBox10.Text = workordernum;
   ModalPopupExtender1.Show();
    DetailsView1.Visible = true;        
 }

我的SqlSource代码

<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:WorkOrderConnectionString4 %>"
DeleteCommand="DELETE FROM [Master] WHERE [WorkOrderNum] = @WorkOrderNum"
InsertCommand="UPDATE [Master] SET [WorkPerformed / PartsUsed] = @column1, [Work Completed By :] = @column2, [Maint. Supv. Approval] = @column3, [Q.C. Inspection By:] = @column4, [Work Comp Date] = @Work_Comp_Date, [Supv Approval Date] = @Supv_Approval_Date, [Safety Inspected By] = @Safety_Inspected_By, [Status] = @Status, [Maint. Supv. Approval Date] = @column5 WHERE [WorkOrderNum] = @WorkOrderNum"
SelectCommand="SELECT [WorkOrderNum], [WorkPerformed / PartsUsed], [Work Completed By :] , [Maint. Supv. Approval], [Q.C. Inspection By:], [Work Comp Date] AS Work_Comp_Date, [Supv Approval Date] AS Supv_Approval_Date, [Safety Inspected By] AS Safety_Inspected_By, [Status], [Maint. Supv. Approval Date] FROM [Master]"


UpdateCommand="UPDATE [Master] SET [WorkPerformed / PartsUsed] = @column1, [Work Completed By :] = @column2, [Maint. Supv. Approval] = @column3, [Q.C. Inspection By:] = @column4, [Work Comp Date] = @Work_Comp_Date, [Supv Approval Date] = @Supv_Approval_Date, [Safety Inspected By] = @Safety_Inspected_By, [Status] = @Status, [Maint. Supv. Approval Date] = @column5 WHERE [WorkOrderNum] = @WorkOrderNum">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox10" Name="WorkOrderNum2"
PropertyName="Text" Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="column1" Type="String" />
<asp:Parameter Name="column2" Type="String" />
<asp:Parameter Name="column3" Type="String" />
<asp:Parameter Name="column4" Type="String" />
<asp:Parameter DbType="Date" Name="Work_Comp_Date" />
<asp:Parameter DbType="Date" Name="Supv_Approval_Date" />
<asp:Parameter Name="Safety_Inspected_By" Type="String" />
<asp:Parameter Name="Status" Type="String" />
<asp:Parameter DbType="Date" Name="column5" />
<asp:ControlParameter ControlID="TextBox10" Name="WorkOrderNum"
PropertyName="Text" />
</InsertParameters>
<DeleteParameters>
<asp:ControlParameter ControlID="TextBox10" Name="WorkOrderNum"
PropertyName="Text" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="column1" Type="String" />
<asp:Parameter Name="column2" Type="String" />
<asp:Parameter Name="column3" Type="String" />
<asp:Parameter Name="column4" Type="String" />
<asp:Parameter DbType="Date" Name="Work_Comp_Date" />
<asp:Parameter DbType="Date" Name="Supv_Approval_Date" />
<asp:Parameter Name="Safety_Inspected_By" Type="String" />
<asp:Parameter Name="Status" Type="String" />
<asp:Parameter DbType="Date" Name="column5" />
<asp:Parameter Name="WorkOrderNum" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:WorkOrderConnectionString3 %>"


SelectCommand="SELECT WorkOrderNum, Requestor, Date, Department, CompletionDate, MachineDescription, MachineLocation, [Type of Work Order], [Work Required], [WorkPerformed / PartsUsed], [Work Completed By :], [Maint. Supv. Approval], [Q.C. Inspection By:], [Work Comp Date], [Supv Approval Date], [Safety Inspected By], Status, [Maint. Supv. Approval Date] FROM Master ORDER BY WorkOrderNum DESC">
</asp:SqlDataSource>

我的问题是为什么提交和取消按钮现在没有触发,它在面板或模态之外触发,是否有我需要更改的设置?

当弹出窗口出现时,也是一种让背景变黑的方法,我真的很新的弹出式概念,我可以在谷歌搜索后完成下面的事情

请帮助:)

1 个答案:

答案 0 :(得分:0)

我终于弄清楚为什么细节视图插入和取消事件没有在详细信息视图中触发,我所要做的就是更改UseSumbitBehavior =“False”

<InsertItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="False"
CommandName="Insert" onclick="Button1_Click" Text="Submit" UseSubmitBehavior="False" />
&nbsp;<asp:Button ID="Button2" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" OnClick="Button2_Click1" UseSubmitBehavior="False" />
&nbsp;
</InsertItemTemplate>

只要将背景改为黑色我就可以通过使用一些CSS来实现这一点:

<style>
.modalBackground
{
    background-color:Gray;
    filter:alpha(opacity=50);
    opacity:0.7;
}
.pnl1BackGround
{
    background-color:White;

}

更改Pop使用X和Y坐标的PopUp的位置,X表示水平移动,Y表示垂直移动。

希望这个答案有助于那里的人:) 快乐的编码家伙