C# asp.net listview에서 이상한 문제가 발생하여 정확한 원인과 문제점을 지적 할 수 없습니다. 시나리오는 다음과 같습니다DataSource가 채워지면 listview는 바인딩하지만 EmptyDataTemplate을 표시합니다.
AutoCompleteExtender를 사용하는 검색 텍스트 상자가 있습니다. PageLoad()에서 DataTable에서 추출 된 데이터 묶음이 목록보기에 채워집니다. 누군가가 텍스트 상자에 뭔가를 입력하면 webservice에서 결과를 가져 와서 DataTable에 결과를 채우면 listview가 DataTable에 바인딩됩니다.
모든 것이 정상적으로 작동합니다. listview는 처음에 제대로 작동하는 DataPager로 바인딩합니다. listview의 첫 번째 페이지에서 사용자가 검색을 입력하면 listview가 바인딩되어 새 결과를 표시합니다.
그러나 두 번째 페이지 이상인 경우 listview는 바인딩되지만 EmptyDataTemplate을 표시합니다. DataTable을 검사하여 listview.DataBind 전에 새 데이터로 채워지는지 확인합니다. 문제는 목록 뷰의 1 페이지에서 벗어날 때만 발생합니다.
ASPX
<asp:ListView ID="productList" runat="server" onitemcommand="productList_ItemCommand" DataKeyNames="PrimaryID">
<LayoutTemplate>
<table>
<tr runat="server">
<th runat="server">Actions</th>
<th runat="server">PrimaryID</th>
<th runat="server">Product</th>
<th runat="server">Description</th>
</tr>
<tr runat="server" id="itemPlaceholder" />
</table>
<asp:DataPager runat="server" ID="productDataPager" PageSize="20" PagedControlID="productList" QueryStringField="pageNumber">
<Fields>
<asp:NextPreviousPagerField ButtonType="Image" ShowFirstPageButton="true" ShowNextPageButton="false" ShowPreviousPageButton="false" FirstPageText="|<< " />
<asp:NumericPagerField ButtonCount="10" />
<asp:NextPreviousPagerField ButtonType="Image" ShowLastPageButton="true" ShowNextPageButton="false" ShowPreviousPageButton="false" LastPageText=" >>|" />
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<tr id="Tr1" class="even" runat="server">
<td>
<asp:LinkButton ID="EditButton" runat="Server" Text="Edit" CommandName="Edit_product"/>
</td>
<td">
<asp:Label ID="primarylbl" runat="Server" Text='<%#Bind("PrimaryID") %>' />
</td>
<td>
<asp:Label ID="productlbl" runat="Server" Text='<%#Bind("Product") %>' />
</td>
<td>
<asp:Label ID="descriptionlbl" runat="Server" Text='<%#Bind("Description") %>' /> </td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr id="Tr1" class="odd" runat="server">
<td>
<asp:LinkButton ID="EditButton" runat="Server" Text="Edit" CommandName="Edit_product"/>
</td>
<td>
<asp:Label ID="primarylbl" runat="Server" Text='<%#Bind("PrimaryID") %>' />
</td>
<td>
<asp:Label ID="productlbl" runat="Server" Text='<%#Bind("Product") %>' />
</td>
<td>
<asp:Label ID="descriptionlbl" runat="Server" Text='<%#Bind("Description") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EmptyDataTemplate>
No Records Found
</EmptyDataTemplate>
</asp:ListView>
코드 숨김
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string productkey = "0";
getWeb(productkey); //call WebService to get all Products
}
}
private void createTable(Products[] product)
{
DataTable productTable = new DataTable();
productTable.Columns.Add(new DataColumn("PrimaryID", typeof(string)));
prouctTable.Columns.Add(new DataColumn("Product", typeof(string)));
productTable.Columns.Add(new DataColumn("Description", typeof(string)));
for (int i = 0; i < product.Length; i++)
{
DataRow dr = productTable.NewRow();
dr["PrimaryID"] = product[i].PrimaryID.ToString();
dr["Product"] = product[i].Product.ToString();
dr["Description"] product[i].Description.ToString();
productTable.Rows.Add(dr);
productTable.AcceptChanges();
}
bindtoList(productTable);
protected void bindtoList(DataTable prodTab)
{
if (productList.DataSource == null)
{
productList.DataSource = prodTab;
productList.DataBind();
Updatepanel1.Update();
}
else
{
productList.DataSource = null;
productList.DataSource = proTab;
productList.DataBind();
}
if (prodTab.Rows.Count > 20)
{
((DataPager)productList.FindControl("productDataPager")).Visible = true;
}
else
{
if (((DataPager)productList.FindControl("productDataPager")) != null && ((DataPager)productList.FindControl("productDataPager")).Visible == true)
{
((DataPager)productList.FindControl("productDataPager")).Visible = false;
}
}
}
HTML 마크 업과 코드를 게시 할 수 있습니까 ?? –
코드가 추가되었습니다. 문제가있는 곳에서 당신의 intial take는 무엇입니까? – Dee
이'createTable'이 불려질 때? –