472,958 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Changing the color of a cell in a datalist

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

<asp:DataList 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>
</asp:DataList></asp:Panel>


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;
}
}
Jan 11 '07 #1
2 1456
Hello Steve,

For your scenario, since you bind the DataReader to the DataList rather
than a Dataset/DataTable, you can not convert each DataItem(in
ItemDataBound event) to DataRowview. DataRowView is only available in
DataView(which is generated from DataTable).

In your ItemDataBound code, you can convert the DataItem to "IDataRecord"
interface and retrive column value from it. e.g.

===============
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs
e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
IDataRecord record = e.Item.DataItem as IDataRecord;

int id = (int)record["CategoryID"];
string name = (string)record["CategoryName"];

Response.Write("<br/>id: " + id + ", name: " + name);
}
}
=====================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 11 '07 #2
Thanks Steven,

worked perfectly...
"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:Sr**************@TK2MSFTNGHUB02.phx.gbl...
Hello Steve,

For your scenario, since you bind the DataReader to the DataList rather
than a Dataset/DataTable, you can not convert each DataItem(in
ItemDataBound event) to DataRowview. DataRowView is only available in
DataView(which is generated from DataTable).

In your ItemDataBound code, you can convert the DataItem to "IDataRecord"
interface and retrive column value from it. e.g.

===============
protected void Repeater1_ItemDataBound(object sender,
RepeaterItemEventArgs
e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
IDataRecord record = e.Item.DataItem as IDataRecord;

int id = (int)record["CategoryID"];
string name = (string)record["CategoryName"];

Response.Write("<br/>id: " + id + ", name: " + name);
}
}
=====================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Jan 11 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ehm | last post by:
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic...
6
by: Eric | last post by:
I have an array, result. I populate the array and add it to an ArrayList. I then change result and add the new version to the ArrayList. However, when I go to review the ArrayList, all of the...
0
by: Ramesh | last post by:
I am using a datalist control in my page and it has a header template. In the header template I have a table control with table rows and table cells. While the page is loading I am trying to change...
0
by: Sonny Sablan | last post by:
How do you set the cell width in an itemtemplate loop? I don't seem to have control over the size of the cells... I know I can set the width of the table. <asp:DataList id="Nav"...
3
by: Alan Silver | last post by:
Hello, I have a datalist which I am using to view and modify some data. When the user clicks the "edit" link, the appropriate cell is moved into edit mode, as specified in the EditTemplate. ...
1
by: Paul Say | last post by:
Here is the problem, I have a datalist that builds a list of links horizontally across the screen for a menu bar. i.e <asp:datalist id="menuTabs" runat="server> <ItemTemplate>...
0
by: Alan Silver | last post by:
Hello, I'm sure this is obvious, but it's driving me mad!! I have a DataList, and I want to have the contents of each cell centred and vertically aligned to the bottom of the cell. I have tried...
2
by: RAM | last post by:
Hi, Please help in the following problem: I am writing ASP.NET application containing page on which I include (IN A TABLE CELL) a set of asp:TextBoxs in a <tableand asp:DataList control. I don't...
2
by: mj.redfox.mj | last post by:
Hi, I wonder if someone could possibly help with this? I have the following code, which is a nested repeater in turn nesting a datalist. This all works fine, together with my page-behind vb code...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.