Forum » Programiranje » [.NET ASP] Napaka : Specified cast is not valid
[.NET ASP] Napaka : Specified cast is not valid
pinc ::
Preko ASPNET starter kita od microsofta, bolje receno za trgovino, sem potegnil iz interneta njihov commerce starter kit, da ga bom malo modificiral in ze na zacetku sem naletel na problem, ki ga ne znam resit.
Zadeva je taka da mi vrze naslednji error:
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error:
Line 74: string _output2 = "{0}";
Line 75:
Line 76: DataRowView _row2 = (DataRowView) dataItem2;
Line 77:
Line 78: _output2 = String.Format(_output2,_row2["Description"]);
Enako funkcijo uporabljam tudi drugje pa dela brez problema, kaj je kriv datalist(kar mocno dvomim), so krive shranjene procedure al kaj bi lahko bil problem?
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace ASPNET.StarterKit.Commerce {
public class ProductsList : System.Web.UI.Page {
protected System.Web.UI.WebControls.DataList MyList;
public ProductsList() {
Page.Init += new System.EventHandler(Page_Init);
}
//*******************************************************
//
// The Page_Load event on this page is used to obtain
// from a database a collection of all products within a
// specified product category. The collection is then
// databound to a templated asp:datalist control.
//
// The product category to obtain is specified using
// a querystring argument to the page.
//
// Note that this page is output cached at 1 hour
// intervals. This eliminates the need to hit the database
// on each request to the page.
//
//*******************************************************
private void Page_Load(object sender, System.EventArgs e) {
// Obtain categoryId from QueryString
int categoryId = Int32.Parse(Request.Params["CategoryID"]);
// Obtain products and databind to an asp:datalist control
ASPNET.StarterKit.Commerce.ProductsDB productCatalogue = new ASPNET.StarterKit.Commerce.ProductsDB();
MyList.DataSource = productCatalogue.GetProducts(categoryId);
MyList.DataBind();
}
//zacasno komentiran
/* public string zalogaProduktov(object dataItem)
{
string _output = "{0}";
DataRowView _row = (DataRowView) dataItem;
_output = String.Format(_output,_row["zaloga_produkta"]);
if (_output == "0" || _output == "NULL")
{
_output = "Ni na zalogi";
}
else
{
_output = "Na zalogi!";
}
return _output;
}*/
//MOJ PROBLEM!!!
public string Prikazbesedila(object dataItem2)
{
string _output2 = "{0}";
DataRowView _row2 = (DataRowView) dataItem2;
_output2 = String.Format(_output2,_row2["Description"]);
if (_output2.Length > 50)
{
_output2 = _output2.Substring(0,50);
}
else
{
_output2 = _output2;
}
return _output2;
}
private void Page_Init(object sender, EventArgs e) {
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
}
#region Web Form Designer generated code
/// < summary >
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// < / summary >
private void InitializeComponent() {
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
To je en del kode...
v aspx strani ga pa klicem takole:
< % # Prikazbesedila(Container.DataItem) %>
Prosim za cimhitrejso pomoc.
Lep pozdrav
Zadeva je taka da mi vrze naslednji error:
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error:
Line 74: string _output2 = "{0}";
Line 75:
Line 76: DataRowView _row2 = (DataRowView) dataItem2;
Line 77:
Line 78: _output2 = String.Format(_output2,_row2["Description"]);
Enako funkcijo uporabljam tudi drugje pa dela brez problema, kaj je kriv datalist(kar mocno dvomim), so krive shranjene procedure al kaj bi lahko bil problem?
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace ASPNET.StarterKit.Commerce {
public class ProductsList : System.Web.UI.Page {
protected System.Web.UI.WebControls.DataList MyList;
public ProductsList() {
Page.Init += new System.EventHandler(Page_Init);
}
//*******************************************************
//
// The Page_Load event on this page is used to obtain
// from a database a collection of all products within a
// specified product category. The collection is then
// databound to a templated asp:datalist control.
//
// The product category to obtain is specified using
// a querystring argument to the page.
//
// Note that this page is output cached at 1 hour
// intervals. This eliminates the need to hit the database
// on each request to the page.
//
//*******************************************************
private void Page_Load(object sender, System.EventArgs e) {
// Obtain categoryId from QueryString
int categoryId = Int32.Parse(Request.Params["CategoryID"]);
// Obtain products and databind to an asp:datalist control
ASPNET.StarterKit.Commerce.ProductsDB productCatalogue = new ASPNET.StarterKit.Commerce.ProductsDB();
MyList.DataSource = productCatalogue.GetProducts(categoryId);
MyList.DataBind();
}
//zacasno komentiran
/* public string zalogaProduktov(object dataItem)
{
string _output = "{0}";
DataRowView _row = (DataRowView) dataItem;
_output = String.Format(_output,_row["zaloga_produkta"]);
if (_output == "0" || _output == "NULL")
{
_output = "Ni na zalogi";
}
else
{
_output = "Na zalogi!";
}
return _output;
}*/
//MOJ PROBLEM!!!
public string Prikazbesedila(object dataItem2)
{
string _output2 = "{0}";
DataRowView _row2 = (DataRowView) dataItem2;
_output2 = String.Format(_output2,_row2["Description"]);
if (_output2.Length > 50)
{
_output2 = _output2.Substring(0,50);
}
else
{
_output2 = _output2;
}
return _output2;
}
private void Page_Init(object sender, EventArgs e) {
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
}
#region Web Form Designer generated code
/// < summary >
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// < / summary >
private void InitializeComponent() {
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
To je en del kode...
v aspx strani ga pa klicem takole:
< % # Prikazbesedila(Container.DataItem) %>
Prosim za cimhitrejso pomoc.
Lep pozdrav
- spremenil: kopernik ()
Vesoljc ::
ze eno leto si na temu forumu pa se vedno ne znas pravilno poimanovat temo...
klik
klik
Abnormal behavior of abnormal brain makes me normal...
pinc ::
U hvala, res si mi dosti s tem pomagal!
Ce bom napisal naslov teme proble, ti garantiram da ga bo kliknilo vec folka ko pa ce bom napisal kaj druga...in kaj ves mogoce se najde kdo ki mi bo pomagal in ne tezil zaradi malenkosti...
So what ce sem eno leto na forumu, postal sem lih enih parkrat, ker ga neobiskujem tolikokrat...
Prosim stick to the problem...
lep pozdrav
Ce bom napisal naslov teme proble, ti garantiram da ga bo kliknilo vec folka ko pa ce bom napisal kaj druga...in kaj ves mogoce se najde kdo ki mi bo pomagal in ne tezil zaradi malenkosti...
So what ce sem eno leto na forumu, postal sem lih enih parkrat, ker ga neobiskujem tolikokrat...
Prosim stick to the problem...
lep pozdrav
Vesoljc ::
egoizem na vrhuncu! ce bi rad velik klikov, napisi v naslov free porn...
zakaj mislis da tezimo k imenemo tem, iz katerih se da takoj razbrat za kaj gre? ker se mogoce najde se kdo, ki bo imel podobne tezave. res mislis da bo v search napisal problem...?
zakaj mislis da tezimo k imenemo tem, iz katerih se da takoj razbrat za kaj gre? ker se mogoce najde se kdo, ki bo imel podobne tezave. res mislis da bo v search napisal problem...?
Abnormal behavior of abnormal brain makes me normal...
pinc ::
daj prosim stick to the problem..
ce bos v search napisal recimo tud vsebino mojega posta ala "Cast not valid" ali kaj podobnega ga bo tud naslo, tak da ne mi prosim solate prodajat...ker dvomim da bi tak velik forum ko je to ne imel moznosti iskanja po vsebini threade-a...
Kdo pa sploh isce stran za stranjo svoj problem, redkokdo!
nimam se namena kregat ker sem ze cisto zivcn zaradi tega, ker me stvar ze dva dni jezi in prosim prihrani mi muke...
lep pozdrav!
ce bos v search napisal recimo tud vsebino mojega posta ala "Cast not valid" ali kaj podobnega ga bo tud naslo, tak da ne mi prosim solate prodajat...ker dvomim da bi tak velik forum ko je to ne imel moznosti iskanja po vsebini threade-a...
Kdo pa sploh isce stran za stranjo svoj problem, redkokdo!
nimam se namena kregat ker sem ze cisto zivcn zaradi tega, ker me stvar ze dva dni jezi in prosim prihrani mi muke...
lep pozdrav!
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | C# težavaOddelek: Programiranje | 3702 (2548) | mladec |
» | [js jquery] širina divaOddelek: Programiranje | 1192 (1060) | alexa-lol |
» | c# datagridview in comboxOddelek: Programiranje | 1204 (1092) | OmegaM |
» | ASPX preusmeritvena zankaOddelek: Programiranje | 2113 (2018) | Senzacionale |
» | [ASP.NET]Oddelek: Programiranje | 1320 (1174) | OmegaM |