想要从gridview调用详细信息视图

时间:2015-08-18 21:16:36

标签: c# asp.net gridview modalpopupextender detailview

我有一个带有工作订单的网格视图,其中一半的工作订单detials由请求者输入,另一半是由主管输入

因此主管将审查创建的工作订单,然后在我的gridview中输入他的半个soo我创建了一个名为work on的模板字段,并且当主管点击此按钮我想要详细信息视图时它是一个链接按钮soo作为一个模态弹出来。

我的gridview .aspx代码

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
  AutoGenerateColumns="False" BackColor="#39B1CC" 
  DataSourceID="SqlDataSource1" ForeColor="White" AllowSorting="True" 
  DataKeyNames="WorkOrderNum" PostBack = "True" ShowHeaderWhenEmpty="True" EmptyDataText="There were no work orders created to 
be viewed at this time please create a Work Order"
     onrowupdated="GridView1_RowUpdated" style="margin-right: 0px" 
     PageSize="12">
   <Columns>
   <asp:TemplateField ShowHeader="False">
   <ItemTemplate>
  <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
   CommandName="Select" onclick="LinkButton1_Click" Text="Print"></asp:LinkButton>
   </ItemTemplate>
    </asp:TemplateField>
<asp:TemplateField ShowHeader="False">
  <ItemTemplate>
    <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="false" 
   CommandName="" onclick="LinkButton2_Click" Text="Work On"></asp:LinkButton>
  </ItemTemplate>
  <ControlStyle ForeColor="#0033CC" />
   </asp:TemplateField>
  <asp:BoundField DataField="WorkOrderNum" HeaderText="WorkOrderNum" 
   InsertVisible="False" ReadOnly="True" SortExpression="WorkOrderNum" >
    <HeaderStyle Width="10px" />
    </asp:BoundField>
  <asp:BoundField DataField="Requestor" HeaderText="Requestor" 
   SortExpression="Requestor" />
 <asp:BoundField DataField="Date" 
  HeaderText="Date" SortExpression="Date" dataformatstring="{0:MM/d/yyyy}" />
   <asp:BoundField DataField="Department" HeaderText="Department" 
   SortExpression="Department" />
   <asp:BoundField DataField="CompletionDate" 
    HeaderText="CompletionDate" SortExpression="CompletionDate"  dataformatstring="{0:MM/d/yyyy}"/>
   <asp:BoundField DataField="MachineDescription" HeaderText="MachineDescription" 
 SortExpression="MachineDescription" />
  <asp:BoundField DataField="MachineLocation" HeaderText="MachineLocation" 
   SortExpression="MachineLocation" />
  <asp:BoundField DataField="Type of Work Order" HeaderText="Type of Work Order" 
   SortExpression="Type of Work Order" />
 </Columns>
  </asp:GridView>

我的详细资料view.aspx

<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">
<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:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Work Comp Date Date Field Required" ControlToValidate = "TextBox5"></asp:RequiredFieldValidator>
<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:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Supv.Approval Date Field Required" ControlToValidate = "TextBox6"></asp:RequiredFieldValidator>
<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:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Maint.Supv.Approval Date Field Required" ControlToValidate = "TextBox9"></asp:RequiredFieldValidator>
<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>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 ShowHeader="False">
<EditItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="True"
CommandName="Update" Text="Submit" />
&nbsp;<asp:Button ID="Button2" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</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>

截至目前我有详细信息view1.visible = false 我需要弹出窗口的原因是因为我的gridview占用了整个页面,我需要为主管填写详细信息视图同样。

我的gridview的图片 enter image description here

我的详情视图

enter image description here

所以用户点击&#34; Work On&#34;我希望它将WorkOrderNum作为gridview中的一个参数,并在EnterWorkOrderNumber旁边的文本框中将其设置为相等,如果它可以将详细信息视图显示为一个非常棒的弹出窗口。我真的很抱歉,我没有任何使用AJAX的经验,我在网上看了,但是他们在网格视图之外使用按钮的工作没有多少帮助从gridview调用详细信息视图。

经过大量的谷歌搜索后,我能够从面板内部弹出详细信息视图,如果插入(提交)和取消按钮不起作用,并且面板弹出gridview的中心可以控制弹出位置,我讨厌将这些控件固定在一个地方,我希望能够将它放在我在红色方块中标记的位置:(

enter image description here

完成弹出窗口的额外代码

的.aspx

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit.HTMLEditor" TagPrefix="cc1" %>

<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="pnl1" PopupControlID="pnl1"></asp:ModalPopupExtender>

  <asp:HiddenField ID="HiddenField1" runat="server" />
 <asp:Panel ID="pnl1" runat="server" Width="881px" Height="175px">
<DetailsView1>
 </asp:Panel>

aspx.cs

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
 {           
ImageButton imgbtn = (ImageButton)sender;
GridViewRow GridView1 = (GridViewRow)imgbtn.NamingContainer;
string workordernum = GridView1.Cells[3].Text;
TextBox10.Text = workordernum;
ModalPopupExtender1.Show();
DetailsView1.Visible = true;
}

2 个答案:

答案 0 :(得分:0)

您可以尝试使用Ajax Control Toolkit。它有一个ModalPopup扩展,您可以尝试嵌入您的详细信息视图。您可以通过javascript代码或服务器端代码操作模态窗口。

http://ajaxcontroltoolkit.devexpress.com/ModalPopup/ModalPopup.aspx

答案 1 :(得分: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表示垂直移动。

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