Last post Mar 09, 2012 05:16 AM by ijoshi
Mar 07, 2012 02:16 PM|ijoshi|LINK
I am trying to color the chat columns in different colours according to the person who is sending it.I have useds the gridview to show my chats along with the to_id and from_id field, which are the ids of the people who are chatting.
I found this colde in c#, can someone please convert it to vb and customize according to my needs please?thank you. I want the rows with the same to_id to be of one colour, and rows of same from_id to be of one colour.
Please note this chat is between just two people.
Thanks in advance
void YourGridViewName_RowDataBound(Object sender, GridViewRowEventArgs e)
if(e.Row.RowType == DataControlRowType.DataRow)
int theValue = Convert.ToInt32(e.Row.Cells.Text)
if (theValue > 99)
e.Row.Cells.BackColor = Color.Red
else if (theValue < 10)
e.Row.Cells.BackColor = Color.Yellow;
Mar 07, 2012 04:11 PM|Horizon_Net|LINK
there are several converter available like
Note that they are not perfect. You may have to solve some conversion errors.
Mar 07, 2012 04:21 PM|UstesG|LINK
Select Case e.Row.RowType
Dim theValue As Integer = Convert.ToInt32(e.Row.Cells(1).Text)
If theValue > 99 Then
e.Row.Cells(1).BackColor = Drawing.Color.Red
e.Row.Cells(1).BackColor = Drawing.Color.Yellow
Mar 07, 2012 11:10 PM|ijoshi|LINK
THank you so much, can you please help me with one mmore thing, where do I use this code? I have just a default.aspx page and an entity model.so i put this in default.aspx or default.aspx.vb after Page_load?
I am a comolete newbie ,sorry :|
Mar 08, 2012 10:37 AM|UstesG|LINK
place this in the gridview rowDataboundevent..
Protected Sub yourGridview_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvSchoolCampaigns.RowDataBound
Mar 09, 2012 05:16 AM|ijoshi|LINK
Its working..thank you..here's how i edited it according to my needs :
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
//DataRowView drv = (DataRowView)e.Row.DataItem;//get a reference to the data used to databound row
if (e.Row.Cells.Text == (123).ToString())
e.Row.BackColor = System.Drawing.Color.FromArgb(227,226,225);
e.Row.BackColor = System.Drawing.Color.FromArgb(201,254,169);
But I also wanted to know, can we sumhow ident these cells in addition to changing the color according to these same conditions. if the cell value is123 i want it in one color, and also indented a little on the right, but if it is any other i want it
on the left.
Its kind of a chat app.Its supposed to be similar to whatsapp/blackberry chat..