グリッドビューのページングを設定しましたGuid should contain 32 digits with 4 dashes
が、ページャーで別のページをクリックするとエラーが発生します。分かりやすいエラー メッセージが表示されたら、[OK] をクリックします。グリッドには次のページのデータが表示されます。
デバッグは、このメソッドで例外をキャッチしました:
protected void cntrlGrdVwDisplayProducts_RowCommand ( object sender , GridViewCommandEventArgs e )
{
Guid productID;
try
{
productID = new Guid ( e.CommandArgument.ToString ( ) );
if ( ( ( e.CommandName != null ) & ( e.CommandArgument != null ) ) )
{
switch ( e.CommandName.ToString ( ).ToLower ( ) )
{
case "editproduct":
EditProduct ( productID );
break;
case "deleteproduct":
DeleteProduct ( productID );
break;
case "publishproduct":
string currentStatus = ((LinkButton)e.CommandSource).Text.Trim();
int newStatus = -1;
if ( string.Equals ( currentStatus , "Publish" ) )
{
PublishProduct ( productID , true );
}
else if ( string.Equals ( currentStatus , "UnPublish" ) )
{
PublishProduct ( productID , false );
}
break;
}
}
}
catch ( Exception ex )
{
Forbin.Logging.Log.LogException ( Forbin.Logging.PageType.ProductManage , Forbin.Logging.MessageType.Exception , ex.ToString ( ) );
UIUtils.ShowMessageToUser ( "OnErrorMesg" , this.Page );
}
}
念のため、ページング方法を次に示します。
protected void cntrlGrdVwDisplayProducts_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
cntrlGrdVwDisplayProducts.PageIndex = e.NewPageIndex;
BindDataToUI();
}
グリッドビュー:
<asp:GridView ID="cntrlGrdVwDisplayProducts" runat="server" AutoGenerateColumns="False" AllowPaging="true" PageSize="100" PagerSettings-Mode="NextPreviousFirstLast" OnPageIndexChanging="cntrlGrdVwDisplayProducts_PageIndexChanging" OnRowCommand="cntrlGrdVwDisplayProducts_RowCommand" GridLines="None" OnRowDataBound="cntrlGrdVwDisplayProducts_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Product Name">
<ItemTemplate>
<div class="AdminFontText">
<asp:Label ID="grdLblPrdctName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"ProductName") %>'>
</asp:Label>
</div>
</ItemTemplate>
<HeaderStyle VerticalAlign="Bottom" HorizontalAlign="Left" CssClass="AdminFontHead" />
<ItemStyle VerticalAlign="Top" HorizontalAlign="Left" CssClass="AdminFontText" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Item Number">
<ItemTemplate>
<div class="AdminFontText">
<asp:Label ID="grdLblItemNumber" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"ItemNumber") %>'>
</asp:Label>
</div>
</ItemTemplate>
<HeaderStyle VerticalAlign="Bottom" HorizontalAlign="Left" CssClass="AdminFontHead" />
<ItemStyle VerticalAlign="Top" HorizontalAlign="Left" CssClass="AdminFontText" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<div class="AdminFontText">
<asp:Label ID="grdLblPrdctDescription" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"Description") %>'>
</asp:Label>
</div>
</ItemTemplate>
<HeaderStyle VerticalAlign="Bottom" HorizontalAlign="Left" CssClass="AdminFontHead" />
<ItemStyle VerticalAlign="Top" HorizontalAlign="Left" CssClass="AdminFontText" />
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:LinkButton ID="grdBtnPrdctEdit" runat="server" Text="Edit" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"ProductID") %>'
CommandName="editproduct" CssClass="btn_edit"></asp:LinkButton>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" CssClass="btnFontHead" />
<ItemStyle Width="90" VerticalAlign="Top" HorizontalAlign="Center" CssClass="btnFontHead" />
</asp:TemplateField>
</Columns>
</asp:GridView>
データバインディング方法:
private void BindDataToUI ( )
{
//btnSaveData.Text = "Save";
List<MappedCategoryInfo> categoryMappings = BusinessFactory.GetCategoryManager ( ).GetCategoryMappings ( );
BindCategoryFilters ( cntrlDdlFltrCategory , categoryMappings );
if ( cntrlDdlFltrCategory.Items.Count > 0 )
{
cntrlDdlFltrCategory.SelectedIndex = 0;
cntrlDdlFltrSubCategory.Enabled = false;
List<ProductInfo> allProducts = new List<ProductInfo> ( );
Guid subCategoryID = Guid.Empty;
switch ( cntrlDdlFltrCategory.SelectedItem.Value )
{
case All:
allProducts = BusinessFactory.GetProductManager ( ).GetAllProducts ( );
cntrlDdlFltrSubCategory.Enabled = false;
break;
default:
Guid categoryID = new Guid ( cntrlDdlFltrCategory.SelectedValue );
BindSubcategoryFilters ( categoryID , cntrlDdlFltrSubCategory , categoryMappings );
if ( cntrlDdlFltrSubCategory.Items.Count > 0 )
{
cntrlDdlFltrSubCategory.Enabled = true;
switch ( cntrlDdlFltrSubCategory.SelectedItem.Value )
{
case All:
foreach ( ListItem subCategoryItem in cntrlDdlFltrSubCategory.Items )
{
if ( subCategoryItem.Value != All )
{
subCategoryID = new Guid ( subCategoryItem.Value );
allProducts.AddRange ( BusinessFactory.GetProductManager ( ).GetPublAndUnPublProductBasedOnCategory ( subCategoryID ) );
}
}
break;
default:
subCategoryID = new Guid ( cntrlDdlFltrSubCategory.SelectedItem.Value );
allProducts.AddRange( BusinessFactory.GetProductManager().GetPublAndUnPublProductBasedOnCategory( subCategoryID ) );
break;
}
}
break;
}
NumRecords.InnerText = allProducts.Count.ToString();
cntrlGrdVwDisplayProducts.DataSource = allProducts;
cntrlGrdVwDisplayProducts.DataBind ( );
}
}