I am trying to get a listview
to automatically bind and update data elements. After looking at numerous examples and tutorials, I still can't seem to find what is wrong with my code. The display is working just fine. It is just the update command that fails. Here is my SqlDataSource
node:
<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>
Note that the @VirtualName
parameter is being picked up (but not bound because it is the PK). Here is my asp:ListView
node:
<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>
Any feedback would be appreciated.
-Jesse