我试图让listview
自动绑定和更新数据元素。在查看了大量的示例和教程后,我仍然无法找到我的代码有什么问题。显示器工作正常。只是更新命令失败。这是我的SqlDataSource
节点:
<asp:SqlDataSource ID="MSSQLDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:DBConn%>"
DataSourceMode="DataSet"
SelectCommand="select isnull(visits, 0) as Visits, iis.VirtualName, iis.clientname, iis.devurl, iis.stagingurl , iis.liveurl from iissites iis left join (select count(*) as visits, VirtualName from devvisits group by VirtualName) dv on iis.VirtualName = dv.VirtualName order by visits desc" UpdateCommand="update iissites set clientname = @clientname, stagingurl = @stagingurl where VirtualName = @VirtualName">
<UpdateParameters>
<asp:Parameter Name="clientname" Type="String" />
<asp:Parameter Name="stagingurl" Type="String" />
<asp:Parameter Name="VirtualName" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
请注意,正在拾取@VirtualName
参数(但不绑定,因为它是PK)。这是我的asp:ListView
节点:
<asp:ListView DataSourceID="MSSQLDataSource" runat="server" DataKeyNames="VirtualName">
<LayoutTemplate>
<table cellpadding="1">
<tr id="Tr1" runat="server">
<th> </th>
<th id="Th2">Clent Name</th>
<th id="Th1">Local Site</th>
<th id="Th3">LHits</th>
<th>Staging</th>
</tr>
<tr id="ItemPlaceHolder" runat="server" ></tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr runat="server" class='<%# Container.DataItemIndex % 2 == 0 ? "row" : "row alt" %>'>
<td class="command"><asp:ImageButton ImageUrl="images/edit.jpg" ID="btnEdit" runat="server" Text="Edit" CommandName="Edit" /></td>
<td>
<%#Eval("clientname") ?? "nbsp;" %>
</td>
<td align="left">
<asp:LinkButton ID="LinkButton1" OnCommand="clickLink"
CommandName="devvisits" CommandArgument='<%#Eval("VirtualName") %>'
runat="server" ><%#Eval("VirtualName") ?? "nbsp;"%>
</asp:LinkButton>
</td>
<td align="left">
<%#Eval("Visits") ?? "nbsp;" %>
</td>
<td>
<%#Eval("stagingurl") ?? "nbsp;" %>
</td>
</tr>
</ItemTemplate>
<EditItemTemplate>
<tr id="TrEdit" runat="server">
<td>
<asp:ImageButton ImageUrl="images/cancel.jpg" runat="server" CommandName="Cancel" />
<asp:ImageButton ImageUrl="images/save.jpg" runat="server" ID="UpdateButton" CommandName="Update" />
</td>
<td>
<asp:TextBox ID="clientname" runat="server" Text='<%#Bind("clientname") %>' ></asp:TextBox>
</td>
<td align="left">
<asp:Label ID="VirtualName" runat="server">
<asp:LinkButton ID="LinkButton2" OnCommand="clickLink"
CommandName="devvisits"
CommandArgument='<%#Eval("VirtualName") %>'
runat="server" ><%#Eval("VirtualName") %>
</asp:LinkButton>
</asp:Label>
</td>
<td align="left">
<asp:Label ID="DevHits" runat="server">
<%#Eval("Visits") %>
</asp:Label>
</td>
<td align="left">
<asp:TextBox ID="TextBox2" runat="server" Text='<%#Bind("stagingurl") %>' ></asp:TextBox>
</td>
</tr>
</EditItemTemplate>
</asp:ListView>
任何反馈都将不胜感激。
-Jesse
答案 0 :(得分:0)
我也很努力,发现了一个工作区,但它真的很难看。我从ListView ItemUpdating事件中的控件获取值,将值存储在局部变量中,然后处理objectdatasource Updating事件,使用这些值设置对象的属性。我使用objectdatasource的DataObjectTypeName。不喜欢那个解决方案,但它是唯一对我有用的东西,我可以继续......