你好,我遇到了2个popupcontrol扩展器的问题。它们与Web服务结合使用,以显示数据库中的详细信息。每个扩展器从2个不同的表中获取信息。扩展器都可以正常工作,除非它们遇到具有相同主键编号的行。以下是代码(我删除了大部分信息),希望能够更快地查看:
<cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0" CssClass="ajax__myTab" Width="100%" ScrollBars="Horizontal">
<cc1:TabPanel ID="TabPanel5" runat="server" HeaderText="" Enabled="true">
<HeaderTemplate>Agent Info </HeaderTemplate>
<ContentTemplate>
<asp:GridView ID="GridViewClosedProducts" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px"
CellPadding="5" CellSpacing="1" DataKeyNames="Pkey"
DataSourceID="SqlDataSourceGRClosedProds" ForeColor="Black" GridLines="Vertical"
AllowSorting="True" PageSize="20">
<FooterStyle BackColor="#CCCCCC" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Image runat="server" BorderStyle="None" ID="Image1" ImageUrl="Images\MagnifyingClass.gif" />
<cc1:PopupControlExtender ID="PopupControlExtender1" runat="server" PopupControlID="Panel1" TargetControlID="Image1" DynamicContextKey='<%# Eval("Pkey") %>' DynamicControlID="Panel1" DynamicServiceMethod="GetClosedComment" Position="right">
</cc1:PopupControlExtender>
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
</ItemTemplate>
<HeaderStyle VerticalAlign="Top" BorderWidth="0px" />
<ItemStyle BorderWidth="0px" HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Silver" Font-Bold="True" ForeColor="Black" />
<AlternatingRowStyle BackColor="#CCCCCC" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceGRClosedProds" runat="server"
ConnectionString="<%$ ConnectionStrings:EUCNET00722 %>"
SelectCommand="SELECT * FROM [tblClosedProducts] WHERE ([AgentMainPkey] = @AgentMainPkey) ORDER BY Product, DateClosed">
<SelectParameters>
<asp:ControlParameter ControlID="hdnPkey" Name="AgentMainPkey" PropertyName="Value" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="TabPanel3" runat="server" HeaderText="" Enabled="true">
<HeaderTemplate>Agent Info </HeaderTemplate>
<ContentTemplate>
<asp:GridView ID="GridViewUpdates" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="5"
CellSpacing="1" DataKeyNames="Pkey" DataSourceID="SqlDataSourceGRUpdates" ForeColor="Black"
GridLines="Vertical">
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Image runat="server" BorderStyle="None" ID="Image1" ImageUrl="Images\MagnifyingClass.gif" />
<cc1:PopupControlExtender ID="PopupControlExtenderGVU" runat="server" PopupControlID="Panel1" TargetControlID="Image1" DynamicContextKey='<%# Eval("Pkey") %>' DynamicControlID="Panel1" DynamicServiceMethod="GetUpdateComment" Position="right">
</cc1:PopupControlExtender>
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
</ItemTemplate>
<HeaderStyle VerticalAlign="Top" BorderWidth="0px" />
<ItemStyle BorderWidth="0px" HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Silver" Font-Bold="True" ForeColor="Black" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceGRUpdates" runat="server" ConnectionString="<%$ ConnectionStrings:EUCNET00722 %>" SelectCommand="SELECT * FROM [tblComments] WHERE ([AgentMainPkey] = @AgentMainPkey) ORDER BY DateOfComment DESC" DeleteCommand="delete from tblComments where pkey = @pkey">
<SelectParameters>
<asp:ControlParameter ControlID="hdnPkey" Name="AgentMainPkey" PropertyName="Value" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>
**背后的代码
Protected Sub GridViewClosedProducts_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewClosedProducts.RowCreated
If e.Row.RowType = DataControlRowType.DataRow Then
If Not e.Row.DataItem Is Nothing Then
Dim pce As PopupControlExtender = TryCast(e.Row.FindControl("PopupControlExtender1"), PopupControlExtender)
Dim MyPkey As String = e.Row.DataItem("Pkey")
pce.BehaviorID = MyPkey
Dim img As Image = DirectCast(e.Row.FindControl("Image1"), Image)
Dim OnMouseOverScript As String = String.Format("$find('{0}').showPopup();", MyPkey)
Dim OnMouseOutScript As String = String.Format("$find('{0}').hidePopup();", MyPkey)
img.Attributes.Add("onmouseover", OnMouseOverScript)
img.Attributes.Add("onmouseout", OnMouseOutScript)
End If
End If
End Sub
Protected Sub GridViewUpdates_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewUpdates.RowCreated
If e.Row.RowType = DataControlRowType.DataRow Then
If Not e.Row.DataItem Is Nothing Then
Dim pceGVU As PopupControlExtender = TryCast(e.Row.FindControl("PopupControlExtenderGVU"), PopupControlExtender)
Dim MyPkey As String = e.Row.DataItem("Pkey")
pceGVU.BehaviorID = MyPkey
Dim img As Image = DirectCast(e.Row.FindControl("Image1"), Image)
Dim OnMouseOverScript As String = String.Format("$find('{0}').showPopup();", MyPkey)
Dim OnMouseOutScript As String = String.Format("$find('{0}').hidePopup();", MyPkey)
img.Attributes.Add("onmouseover", OnMouseOverScript)
img.Attributes.Add("onmouseout", OnMouseOutScript)
End If
End If
End Sub
这是IE
呈现代码的方式<img id="ctl00_ContentPlaceHolder2_TabContainer1_TabPanel5_GridViewClosedProducts_ctl10_Image1" onmouseover="$find('48').showPopup();" onmouseout="$find('48').hidePopup();" src="Images\MagnifyingClass.gif" style="border-style:None;border-width:0px;" />
<img id="ctl00_ContentPlaceHolder2_TabContainer1_TabPanel3_GridViewUpdates_ctl02_Image1" onmouseover="$find('48').showPopup();" onmouseout="$find('48').hidePopup();" src="Images\MagnifyingClass.gif" style="border-style:None;border-width:0px;" />
答案 0 :(得分:1)
@Mike:如果可以将前一行的Pkey
值存储在变量中,那么我会做这样的事情 -
Dim MyPkey As Integer = e.Row.DataItem("Pkey")
Dim MyStoredPkey As Integer
If MyPkey <> MyStoredPkey Then
MyStoredPkey = MyPkey
Else
MyPkey = MyPkey + 1
End If
pceGVU.BehaviorID = MyPkey
...如果在存储的变量中找到它,则递增Pkey
。
注意:这几乎是伪代码,因为我的ASP.NET经验非常少。