데이터 소스 컨트롤을 사용하지 않고 (Sorted) GridView (SearchResultsGid)를 채우려합니다. 몇 가지 연구를 수행했는데 그리드를 성공적으로 바인딩하기 위해 데이터 세트와 데이터베이스를 사용해야 할 수도 있습니다. 그러나 어떻게해야하는지 완전히 확신 할 수는 없습니다. 나는 데이터 소스 컨트롤을 사용하는 데 더 익숙하다. ...데이터 소스 컨트롤을 사용하지 않고 GridView Eval 데이터 바인딩
그리드 뷰는 필드가 다른 페이지로의 하이퍼 링크가 될 수 있기 때문에 가능하면 유지하고 싶은 Eval 문을 사용한다. 비록 다른 방법이 있다면, 나는 그것을 시도하고자합니다 ...
SearchResultsGrid의 요점은, 사용자가 텍스트 필드에서 뭔가를 입력 한 다음 "검색"버튼, 그리드를 치는 것입니다 데이터베이스의 모든 관련 결과를 표시합니다. 사용자가보기 위해 추가 한 모든 데이터베이스 항목을 표시하는 중계기가 있지만 현재로서는 관련이 없습니다 (어쨌든 제대로 작동합니다).
도움이 될 것입니다. :) 여기
코드입니다 : 나는 SearchResultsGrid을 채우는 기능에 대한 작업을 시작<table cellpadding="4" cellspacing="0" class="inputForm" width="100%">
<tr><td width="100%"><p align="justify">Select the products that should have this option.</p></td></tr>
<tr>
<td valign="top">
<asp:Label ID="errorLbl" ForeColor="Red" Font-Bold="true" runat="server" Text=""></asp:Label>
<asp:UpdatePanel ID="MainContentAjax" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="section">
<div class="header"><h2><asp:Localize ID="FindProductsCaption" runat="server" Text="Find Products" /></h2></div>
<asp:Panel ID="SearchFormPanel" runat="server" CssClass="content" DefaultButton="SearchButton">
<table class="inputForm">
<tr>
<th class="rowHeader"><cb:ToolTipLabel ID="SearchNameLabel" runat="server" Text="Product Name:" ToolTip="Enter all or part of a product name. Wildcard characters * and ? are accepted." /></th>
<td><asp:TextBox ID="SearchName" runat="server" Text="" /></td>
<th class="rowHeader"><cb:ToolTipLabel ID="ShowImagesLabel" runat="server" Text="Show Thumbnails:" ToolTip="When checked, product images will be displayed in the search results." /></th>
<td><asp:CheckBox ID="ShowImages" runat="server" /></td>
<td><asp:LinkButton ID="SearchButton" runat="server" Text="Search" SkinID="Button" OnClick="SearchButton_Click" /></td>
</tr>
</table>
<cb:SortedGridView ID="SearchResultsGrid" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductId" GridLines="None" SkinID="PagedList" Width="100%" AllowPaging="true" Visible="false" DefaultSortExpression="Name" EnableSortingAndPagingCallbacks="True" PageIndex="0" AllowSorting="True">
<Columns>
<asp:TemplateField HeaderText="Thumbnail">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:HyperLink ID="NodeImageLink" runat="server" NavigateUrl='<%# UrlGenerator.GetBrowseUrl((int)Eval("ProductId"), CatalogNodeType.Product, (string)Eval("Name")) %>'> <asp:Image ID="NodeImage" runat="server" ImageUrl='<%# Eval("ThumbnailUrl") %>' Visible='<%# !string.IsNullOrEmpty((string)Eval("ThumbnailUrl")) %>' AlternateText='<%# Eval("Name") %>' /> </asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SKU" SortExpression="Sku">
<HeaderStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:HyperLink ID="ProductSku" runat="server" Text='<%#Eval("Sku")%>' SkinID="FieldHeader" /><br />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Item" SortExpression="Name" >
<HeaderStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:HyperLink ID="ProductName" runat="server" Text='<%#Eval("Name")%>' SkinID="FieldHeader" /><br />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Assigned">
<ItemStyle Width="50px" HorizontalAlign="Center" />
<ItemTemplate>
<asp:ImageButton ID="AttachButton" runat="server" CommandArgument='<%#Container.DataItemIndex%>' AlternateText="Add" ToolTip="Add" SkinID="AddIcon" OnClientClick="this.visible=false" OnClick="AttachButton_Click" Visible='<%#!IsProductLinked(((Product)Container.DataItem).ProductId)%>' />
<asp:ImageButton ID="RemoveButton" runat="server" CommandArgument='<%#Container.DataItemIndex%>' AlternateText="Remove" ToolTip="Remove" SkinID="DeleteIcon" OnClientClick="return confirm('Are you sure you want to remove this item from this option?')" OnClick="RemoveButton_Click" Visible='<%#IsProductLinked(((Product)Container.DataItem).ProductId)%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
There are no products that match the search text.
</EmptyDataTemplate>
</cb:SortedGridView>
</asp:Panel>
</div>
<div class="section">
<div class="header"><h2>Assigned Products</h2></div>
<div class="content">
<asp:Repeater ID="RelatedProductGrid" runat="server" SkinID="PagedList" OnItemCommand="RelatedProductGrid_RowDeleting">
<HeaderTemplate>
<table width="100%" class="pagedList" cellpadding="0" cellspacing="0">
</HeaderTemplate>
<ItemTemplate>
<tr class="oddRow">
<td>
<asp:Label ID="ProdID" runat="server" Text='<%#Eval("ProductId") %>' Visible="false" />
<asp:HyperLink ID="ProductName2" runat="server" Text='<%#Eval("Name")%>' NavigateUrl='<%#Eval("ProductId", "/Admin/products/EditProduct.aspx?ProductId={0}")%>' />
</td>
<td><asp:ImageButton ID="RemoveButton2" runat="server" SkinID="DeleteIcon" CommandName="Delete" CommandArgument='<%#Eval("ProductId") %>' AlternateText="Remove" ToolTip="Remove" OnClientClick="return confirm('Are you sure you want to remove this item from this option?')" /></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr class="evenRow">
<%-- <td>
<asp:Label ID="ProdID2" runat="server" Text='<%#Eval("ProductId") %>' Visible="false" />
<asp:HyperLink ID="ProductSku" runat="server" Text='<%#Eval("Sku")%>' NavigateUrl='<%#Eval("ProductId", "/Admin/products/EditProduct.aspx?ProductId={0}")%>' />
</td>--%>
<td>
<asp:Label ID="ProdID" runat="server" Text='<%#Eval("ProductId") %>' Visible="false" />
<asp:HyperLink ID="ProductName2" runat="server" Text='<%#Eval("Name")%>' NavigateUrl='<%#Eval("ProductId", "/Admin/products/EditProduct.aspx?ProductId={0}")%>' />
</td>
<td><asp:ImageButton ID="RemoveButton2" runat="server" SkinID="DeleteIcon" CommandName="Delete" CommandArgument='<%#Eval("ProductId") %>' AlternateText="Remove" ToolTip="Remove" /></td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</div>
<asp:Button ID="FinishButton" runat="server" Text="Finish" OnClick="FinishButton_Click" /><br />
<br />
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
하고, SQL 명령은 내가 버튼을 클릭에 대한 정확한 정보를 얻기의 측면에서 수하는 방법입니다 . 버튼 클릭 내에서이 함수를 호출 할 계획입니다.
protected void PopulateSearchGrid()
{
try
{
System.Data.SqlClient.SqlDataReader dr = null;
DataSet ds = new DataSet();
DataTable resultsTbl = ds.Tables.Add("resultsTbl");
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["AbleCommerce"].ToString()))
{
using (SqlDataAdapter sda = new SqlDataAdapter("SELECT OptionID, ac_Products.Name, Sku FROM ac_Options, ac_Products WHERE OptionID = @OptionID AND ac_Products.Name = @Name", cn))
{
///and this is where I'm getting confused on what to do :(
}
}
}
catch { }
}
감사합니다! 이로 인해 문제가 해결되었습니다. –