S
sck10
Hello,
I am populating a DataList with data from a stored procedure. What I am
trying to do is change the color based on the one of the values that the
stored procedure sends.
When I try to use the method "protected void
dlstTransformation_ItemDataBound(object sender, DataListItemEventArgs e)",
I get the error: System.Data.Common.DbDataRecord' to type
'System.Data.DataRowView'.
Any help with this would be appreciated.
sck10
<aspataList id="dlstTransformation" Runat="Server"
OnItemDataBound="dlstTransformation_ItemDataBound"
GridLines="Both"
CellPadding="1"
CellSpacing="3"
RepeatColumns="4"
RepeatDirection="Horizontal">
<ItemTemplate>
<asp:Label ID="lblTransformation" runat="server" Text='<%#
Eval("ServiceLink") %>' />
</ItemTemplate>
</aspataList></aspanel>
protected void Transformation(string str00, string str01, string str02,
string str03, string str04)
{
string strCatchName = "Transformation";
try
{
//'Open connection to database
using(SqlConnection cnnSearch = new
SqlConnection(strConnSQLFundTrack))
{
cnnSearch.Open();
SqlCommand cmdSearch = new SqlCommand(str00, cnnSearch);
cmdSearch.CommandType = CommandType.StoredProcedure;
//'Declare Parameters
cmdSearch.Parameters.AddWithValue("@strParm01", str01);
cmdSearch.Parameters.AddWithValue("@strParm02", str02);
cmdSearch.Parameters.AddWithValue("@strParm03", str03);
cmdSearch.Parameters.AddWithValue("@strParm04", str04);
SqlDataReader sdrSearch = cmdSearch.ExecuteReader();
dlstTransformation.DataSource = sdrSearch;
dlstTransformation.DataBind();
//To re-read the data, close Reader and re-open
sdrSearch.Close();
sdrSearch = cmdSearch.ExecuteReader();
if(sdrSearch.HasRows)
{
this.pnlTransformation.Visible = true;
this.lblTransformation.Text = strCatchName;
//this.lblServiceDscr.Text =
this.lblServiceDscr.Text.Replace("\r\n", "<br/>").Trim();
} //Loop
} // end using
} // end try
catch(Exception ex)
{
this.AppCodeHidePanels();
this.pnlMessage.Visible = true;
this.lblMessageTitle.Text = "Stored Procedure Error";
this.lblMessageText.Text =
"<span class=BlkB>Problems with stored procedure:</span> " +
"<span class=BlkB>" + strCatchName + "</span><br />" +
ex.Message.ToString();
}
finally
{
// can place something here that will always be fire.
}
} // end void
protected void dlstTransformation_ItemDataBound(object sender,
DataListItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
System.Data.DataRowView drv = (DataRowView)(e.Item.DataItem);
string strBackColor = drv.Row["StatusColor"].ToString();
e.Item.BackColor = System.Drawing.Color.Black;
}
}
I am populating a DataList with data from a stored procedure. What I am
trying to do is change the color based on the one of the values that the
stored procedure sends.
When I try to use the method "protected void
dlstTransformation_ItemDataBound(object sender, DataListItemEventArgs e)",
I get the error: System.Data.Common.DbDataRecord' to type
'System.Data.DataRowView'.
Any help with this would be appreciated.
sck10
<aspataList id="dlstTransformation" Runat="Server"
OnItemDataBound="dlstTransformation_ItemDataBound"
GridLines="Both"
CellPadding="1"
CellSpacing="3"
RepeatColumns="4"
RepeatDirection="Horizontal">
<ItemTemplate>
<asp:Label ID="lblTransformation" runat="server" Text='<%#
Eval("ServiceLink") %>' />
</ItemTemplate>
</aspataList></aspanel>
protected void Transformation(string str00, string str01, string str02,
string str03, string str04)
{
string strCatchName = "Transformation";
try
{
//'Open connection to database
using(SqlConnection cnnSearch = new
SqlConnection(strConnSQLFundTrack))
{
cnnSearch.Open();
SqlCommand cmdSearch = new SqlCommand(str00, cnnSearch);
cmdSearch.CommandType = CommandType.StoredProcedure;
//'Declare Parameters
cmdSearch.Parameters.AddWithValue("@strParm01", str01);
cmdSearch.Parameters.AddWithValue("@strParm02", str02);
cmdSearch.Parameters.AddWithValue("@strParm03", str03);
cmdSearch.Parameters.AddWithValue("@strParm04", str04);
SqlDataReader sdrSearch = cmdSearch.ExecuteReader();
dlstTransformation.DataSource = sdrSearch;
dlstTransformation.DataBind();
//To re-read the data, close Reader and re-open
sdrSearch.Close();
sdrSearch = cmdSearch.ExecuteReader();
if(sdrSearch.HasRows)
{
this.pnlTransformation.Visible = true;
this.lblTransformation.Text = strCatchName;
//this.lblServiceDscr.Text =
this.lblServiceDscr.Text.Replace("\r\n", "<br/>").Trim();
} //Loop
} // end using
} // end try
catch(Exception ex)
{
this.AppCodeHidePanels();
this.pnlMessage.Visible = true;
this.lblMessageTitle.Text = "Stored Procedure Error";
this.lblMessageText.Text =
"<span class=BlkB>Problems with stored procedure:</span> " +
"<span class=BlkB>" + strCatchName + "</span><br />" +
ex.Message.ToString();
}
finally
{
// can place something here that will always be fire.
}
} // end void
protected void dlstTransformation_ItemDataBound(object sender,
DataListItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
System.Data.DataRowView drv = (DataRowView)(e.Item.DataItem);
string strBackColor = drv.Row["StatusColor"].ToString();
e.Item.BackColor = System.Drawing.Color.Black;
}
}