用户代码未对NullreferenceException进行处理:未将对象引用设置为对象的实例 [英] NullreferenceException was unhandled by user code :Object reference not set to an instance of an object
本文介绍了用户代码未对NullreferenceException进行处理:未将对象引用设置为对象的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我正在开发一个小项目并使用devexpress工具。我没有得到正确的代码来获取我的代码中的列值。请帮助我
此处出错:string cid = row.EvalDataItem(HouseImageID)。ToString();
Hi There,
I am working a small project and using devexpress tool.I am not getting correct code to get the value of a column in my code.Please,help me
Error here: string cid = row.EvalDataItem("HouseImageID").ToString();
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BuckshawObjects.Global;
using BuckshawObjects.Objects;
using DevExpress.Web.ASPxEditors;
using System.IO;
using DevExpress.Web.ASPxDataView;
using System.Collections;
using DevExpress.Web.ASPxGridView;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using DevExpress.XtraRichEdit.API.Native;
using System.Drawing;
namespace Buckshaw.Backend
{
public partial class WebForm5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void chkStatus_OnCheckedChanged(object sender, EventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["BuckshawHomesConnectionString"].ConnectionString;
ASPxCheckBox chkStatus = (ASPxCheckBox)sender;
//ASPxDataView row = (ASPxDataView)chkStatus.NamingContainer;
DataViewItemTemplateContainer row=(DataViewItemTemplateContainer)chkStatus.NamingContainer;
//string cid = row.Controls[0].ToString();
//string cod =(row.ItemIndex+1).ToString();
//string cod = row.ItemIndex.ToString();
//string cod = dataView.FindControl("HouseImageID").ToString();
//string cid = dataView.Controls[0].ToString();
//string cod = dataView.Items[0].DataItem.ToString();
string cid = row.EvalDataItem("HouseImageID").ToString();
//string cid = "True";
bool status = chkStatus.Checked;
string query = "UPDATE [tblHouseImage] SET Active = @Approved WHERE HouseImageID = @HouseImageID";
//WHERE HouseImageID = @HouseImageID"
SqlConnection con = new SqlConnection(constr);
SqlCommand com = new SqlCommand(query, con);
com.Parameters.AddWithValue("@Approved", status);
com.Parameters.AddWithValue("@HouseImageID", cid);
con.Open();
com.ExecuteNonQuery();
con.Close();
dataView.DataBind();
}
}
}
推荐答案
如果查看文档: HTTPS ://help.devexpress.com/#AspNet/DevExpressWebASPxClassesItemTemplateContainerBase_EvalDataItemtopic [ ^ ]你会看到EvalDataItme的参数是一个表达式 - 所以有可能它需要更多的东西,比如
If you look at the documentation: https://help.devexpress.com/#AspNet/DevExpressWebASPxClassesItemTemplateContainerBase_EvalDataItemtopic[^] you will see that the parameter to EvalDataItme is an Expression - so the chances are that it wants somethign a little more like
HouseImageId=666
比
Than
HouseImageId
作为参数......
as a parameter...
这篇关于用户代码未对NullreferenceException进行处理:未将对象引用设置为对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文