最近做一个项目,用到页面传值,代码出来以后,运行出了问题,提示:字符串格式不正确,请问各位大大原因,谢谢了!代码如下:html:
<asp:DataList ID="DataList1" runat="server" Height="222px"
RepeatDirection="Horizontal" Width="756px" RepeatColumns="5" >
<ItemTemplate>
<a href="/Model/Product/ProductDetail.aspx?id=productID">
<img src='<%# DataBinder.Eval(Container.DataItem, "pic")%>' />
</a>
</ItemTemplate>
</asp:DataList>
这是用datalist绑定图片,然后他图片有个链接,然后传值过去。本页cs代码: protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
databinding();
getinfo();
}
} protected void databinding()
{
JustyleOnline.Model.Product.Business.Product pro = new JustyleOnline.Model.Product.Business.Product();
DataSet ds= pro.GetNewProduct();
//string str = ds.Tables[0].Rows.Count.ToString();
//JustyleOnline.Core.JS.Alert(str);
DataList1.DataSource = ds.Tables[0].DefaultView;
DataList1.DataBind();
}这是页面的数据绑定代码,其中获取到product的一些值。接下来是接受页面的代码: if (!Page.IsPostBack)
{
//显示更新数据
//若ID为空,则修改管理员自己的信息
if (Request.QueryString["ID"] == null)
{
}
else
{
productID = Convert.ToInt32(Request.QueryString["ID"].ToString());//就是在这一步提示字符串的格式不正确的错误。
}附:productID这个字段的数据类型是int型
求助各位!!!
<asp:DataList ID="DataList1" runat="server" Height="222px"
RepeatDirection="Horizontal" Width="756px" RepeatColumns="5" >
<ItemTemplate>
<a href="/Model/Product/ProductDetail.aspx?id=productID">
<img src='<%# DataBinder.Eval(Container.DataItem, "pic")%>' />
</a>
</ItemTemplate>
</asp:DataList>
这是用datalist绑定图片,然后他图片有个链接,然后传值过去。本页cs代码: protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
databinding();
getinfo();
}
} protected void databinding()
{
JustyleOnline.Model.Product.Business.Product pro = new JustyleOnline.Model.Product.Business.Product();
DataSet ds= pro.GetNewProduct();
//string str = ds.Tables[0].Rows.Count.ToString();
//JustyleOnline.Core.JS.Alert(str);
DataList1.DataSource = ds.Tables[0].DefaultView;
DataList1.DataBind();
}这是页面的数据绑定代码,其中获取到product的一些值。接下来是接受页面的代码: if (!Page.IsPostBack)
{
//显示更新数据
//若ID为空,则修改管理员自己的信息
if (Request.QueryString["ID"] == null)
{
}
else
{
productID = Convert.ToInt32(Request.QueryString["ID"].ToString());//就是在这一步提示字符串的格式不正确的错误。
}附:productID这个字段的数据类型是int型
求助各位!!!
接受页面的那个判断语句,已经有判断是不是有接收到值。
{
}
else
{
productID = Convert.ToInt32(Request.QueryString["ID"].ToString());//就是在这一步提示字符串的格式不正确的错误。
}
应该这样写
if (Request.QueryString["id"] == null)
{
}
else
{
productID = Convert.ToInt32(Request.QueryString["id"].ToString());
}
你这样传过去的值是productID,当然不能转换成int型了。。
<a href="/Model/Product/ProductDetail.aspx?id=<%=productID%>">试试而且
productID = Convert.ToInt32(Request.QueryString["ID"].ToString());
你这里的ID要注意大小写,应该是一致的,即使没影响代码标准些有好处的。
1l兄,不好意思啊,你的代码可以,我用它解决了
咳咳,7l,你的那句“<%=productID%>”,貌似有些问题
OK,没事,都有分,虽然不多,大奖将就着吧
谢谢了