Click here to Skip to main content
15,903,817 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
 css is not remain same as i want to diiferent row have diffrent css randomly on any row not like alternating css.i am writing code below that have problem.
 protected void gvstatus_RowDataBound(object sender, GridViewRowEventArgs e)
        {
           
            if (e.Row.RowType == DataControlRowType.DataRow)
            { if (cab.Rows[i]["language"].ToString() == "H")
                 {
                  gvstatus.HeaderStyle.CssClass = "FontEnglish";
                  gvstatus.RowStyle.CssClass = "NewFont1";
                }
              else
                 {

                     gvstatus.HeaderStyle.CssClass = "FontEnglish";
                     gvstatus.RowStyle.CssClass = "FontEnglish";
                 }

}

}

my problem that css at last row applied is work on whole grid.i want particular row's css diffrent from other row.
Posted
Updated 15-Apr-13 18:53pm
v4
Comments
ZurdoDev 15-Apr-13 10:01am    
Yes, tr elements can have different css classes. You could also use the alternating row template. What have you tried and where are you stuck? Sometimes it is a lot faster to just try something instead of waiting for someone on the internet to answer.
Sergey Alexandrovich Kryukov 15-Apr-13 10:44am    
Golden words...
—SA
satpal 2 16-Apr-13 0:50am    
But css is not remain same as i want to diiferent row have diffrent css randomly on any row not like alternating css.i am writing code below that have problem.
protected void gvstatus_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{ if (cab.Rows[i]["language"].ToString() == "H")
{
gvstatus.HeaderStyle.CssClass = "FontEnglish";
gvstatus.RowStyle.CssClass = "NewFont1";
}
else
{

gvstatus.HeaderStyle.CssClass = "FontEnglish";
gvstatus.RowStyle.CssClass = "FontEnglish";
}

}

}

my problem that css at last row applied is work on whole grid.i want particular row's css diffrent rom other row.

Yes, possible. And as you said yourself, set them as you need in RowDataBound event method.
 
Share this answer
 
Comments
satpal 2 16-Apr-13 0:51am    
But css is not remain same as i want to diiferent row have diffrent css randomly on any row not like alternating css.i am writing code below that have problem.
protected void gvstatus_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{ if (cab.Rows[i]["language"].ToString() == "H")
{
gvstatus.HeaderStyle.CssClass = "FontEnglish";
gvstatus.RowStyle.CssClass = "NewFont1";
}
else
{

gvstatus.HeaderStyle.CssClass = "FontEnglish";
gvstatus.RowStyle.CssClass = "FontEnglish";
}

}

}

my problem that css at last row applied is work on whole grid.i want particular row's css diffrent rom other row.
Sandeep Mewara 16-Apr-13 4:33am    
This is because you set grid'srowstyle CSS... just set at row level. You have a row at hand, set a css on that row.
C#
protected void gvstatus_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            gvstatus.HeaderStyle.CssClass = "FontEnglish";
            if (e.Row.RowType == DataControlRowType.DataRow)
            { 

DataRow dr = (DataRow)e.Row.DataItem;
            if (dr["language"].ToString() == "H")
                e.Row.CssClass = "NewFont1";
            else
                e.Row.CssClass = "FontEnglish";
}

}


Hope this help.

Thanks
Prashant
 
Share this answer
 
v3
Comments
satpal 2 16-Apr-13 1:19am    
this is not working
PrashantSonewane 16-Apr-13 1:23am    
can u pests your css class code.
satpal 2 16-Apr-13 1:41am    
yes .

.NewFont1
{ border:solid 1px #d3cfc7; background:#fff; padding:3px;
-moz-border-radius:4px; -webkit-border-radius:4px; border-radius: 4px;
font-family:'DevLys 010';
font-size: 15px;
src:url('~/Designer/KRDV010.eot')/*url('~/Designer/DEVLYS0.eot');*/;
width: 75px;
}

.FontEnglish{font-family: Verdana, sans-serif;
font-size:11px;
line-height:14px;
color: #787878
}

except this i am pasting whole rowdatabound

protected void gvstatus_RowDataBound(object sender, GridViewRowEventArgs e)
{
gvstatus.HeaderStyle.CssClass = "FontEnglish";
if (e.Row.RowType == DataControlRowType.DataRow)
{

e.Row.Cells[0].CssClass = "FontEnglish";
e.Row.Cells[13].CssClass = "FontEnglish";
e.Row.Cells[15].CssClass = "FontEnglish";
e.Row.Cells[16].CssClass = "FontEnglish";
e.Row.Cells[2].CssClass = "FontEnglish";
e.Row.Cells[5].CssClass = "FontEnglish";

DataTable cab = (DataTable)Session["tab"];

for (int i = 0; i < cab.Rows.Count; i++)
{



if (cab.Rows[i]["language"].ToString() == "H")
e.Row.CssClass = "NewFont1";
else
e.Row.CssClass = "FontEnglish";

}


if (e.Row.RowIndex != gvstatus.EditIndex)
{
LinkButton lnkview = (LinkButton)e.Row.Cells[0].Controls[0];

DataTable tab = (DataTable)Session["tab"];

for (int i = 0; i < tab.Rows.Count; i++)
{
if (tab.Rows[i]["FAdesignationid"].ToString() == "0" && tab.Rows[i]["SAdesignationid"].ToString() == "0")
{
if (tab.Rows[i]["RedressalAuthority"].ToString() == Session["OfficerID"].ToString())
{
lnkview.Enabled = true;
Session["view"] = true;
}
else
{

Session["view"] = false;
}


}
if (tab.Rows[i]["SAdesignationid"].ToString() == "0" && tab.Rows[i]["CaseToFA"].ToString() == "True")
{
if (tab.Rows[i]["FAdesignationid"].ToString() == Session["OfficerID"].ToString())
{
lnkview.Enabled = true;
Session["view"] = true;
}
else
{

Session["view"] = false;
}

}
if (tab.Rows[i]["CaseToSA"].ToString() == "True")
{
if (tab.Rows[i]["SAdesignationid"].ToString() == Session["OfficerID"].ToString())
{
lnkview.Enabled = true;
Session["view"] = true;
}
else
{

Session["view"] = false;
}

}


}
}

}
else if(e.Row.RowType == DataControlRowType.Header)
{
gvstatus.HeaderStyle.CssClass="FontEnglish";
}
}
PrashantSonewane 16-Apr-13 1:57am    
DataTable cab = (DataTable)Session["tab"];

for (int i = 0; i < cab.Rows.Count; i++)
{



if (cab.Rows[i]["language"].ToString() == "H")
e.Row.CssClass = "NewFont1";
else
e.Row.CssClass = "FontEnglish";

}


You have to work on this part. You are looping through datatable's rows and expect gridview row css change. Where you are checking the datatable's rowindex is matching with current gridview row index? So all rows in gridview will get datatable's last row condition satisfied and hence only once css will be applied for all rows.
satpal 2 16-Apr-13 2:02am    
how to do that Prashant?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900