find out the exact type by debugging the code.
check out
http://www.velocityreviews.com/forum...ast-error.html
Regards,
Augustin
http://augustinprasanna.blogspot.com
"AJ" wrote:
> Hi All,
>
> I am having a problem with the following code:
>
> During the Item Bound event is am getting a 'Cast' error for this line:
> if(!((DbDataRecord)e.Item.DataItem).IsDBNull(2))
>
> Any thoughts why this is happening?
>
> Cheers,
> Adam
>
> private DataView GetEnrollments()
> {
>
> //create db connection
> SqlConnection Cn = new
> SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
>
> //open db connection
> Cn.Open();
>
> //sql command to retrieve students
> SqlCommand cmdGetElligibleStudents = new
> SqlCommand("GetElegibleStudents",Cn);
> cmdGetElligibleStudents.CommandType = CommandType.StoredProcedure;
> cmdGetElligibleStudents.Parameters.Add("@CourseID",
> Request.QueryString["CourseID"]);
>
> DataSet dsElligibleStudents = new DataSet();
>
> DataAdapter daElligibleStudents = new
> SqlDataAdapter(cmdGetElligibleStudents);
> daElligibleStudents.Fill(dsElligibleStudents);
>
> //create DataView out of DataSource
> DataView dvEnrollments = new DataView(dsElligibleStudents.Tables[0]);
>
> //close db connection
> Cn.Close();
>
> return dvEnrollments;
>
> }
>
> public void dgEnrollments_ItemBound(object sender, DataGridItemEventArgs e)
> {
>
> if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
> ListItemType.AlternatingItem)
> {
>
> if(!((DbDataRecord)e.Item.DataItem).IsDBNull(2))
> {
>
> ((CheckBox)e.Item.FindControl("chkEnrolled")).Checked = true;
>
> }
>
> }