Asp.net Web应用程序 [英] Asp.net Web Application

查看:66
本文介绍了Asp.net Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好专家:



如何根据某些条件将几行gridview变成不同的颜色。



条件:



登录页面后,用户可以看到带有所有细节的gridview,例如



EmpID,Task,StartDate,EndDate(显示所有员工详细信息)



现在突出显示使用UserID登录的特定用户的详细信息来自所有人的EmpID(我将Empid值作为会话ID)。



怎么做。

解决方案

亲爱的朋友,



这种颜色变化可以在GridRowDataBound事件中实现。当数据被绑定到GridView时,会触发 GridView1_RowDataBound evetn,它将每一行绑定到DataTable或DataSet对象中的数据绑定到Grid。



根据您的情况,您可以相应地更改不同行的coor。对于例如

  protected   void  DrugGridView_RowDataBound( object  sender,GridViewRowEventArgs e)
{
if (e.Row.RowType = DataControlRowType .DataRow)
{
// 检查条件,检查会话中的员工ID
If((UserID = Session [ UserAuthentication]。ToString() ))
{
e.Row.BackColor = Drawing.Color.Red // 这将让行回红色
}
}
}





这里排包含来自DataTable或DataSet的Employee ID可以根据Session Employee ID(根据您的问题登录)进行检查。如果条件匹配,则可以根据需要相应地更改行颜色。



供您参考: - change-gridview-row-color-based-on-condition-in-c-sharp


请不要忘记将此标记为您的答案,如果它可以帮助您。



问候



Varun Sareen




请看看..它会为你锻炼.. 。



设计一个login.aspx页面



]]>


嗨朋友,



查看此代码。非常简单



< pre lang =cs> protected void GridView1_RowDataBound( object sender,GridViewRowEventArgs e)
{
foreach (GridViewRow gvr in GridView1.Rows)
{
if (gvr.RowType == DataControlRowType.DataRow)
{

// gvr.Cells [0] .Text =其中empid显示在gridview中(根据你的//设计更改单元格[index])
// 会话[userid] =您从登录页面传递的会话值

if (gvr.Cells [ 0 ]。文本==会话[ userid]。ToString())
{
gvr.BackColor = System.Drawing.Color.Pink;


}
}


}


}


Hello Experts:

How can i change few rows of gridview into different color basing on some condition.

Condition:

After login page the user is allowed to see the gridview carrying all the details like

EmpID,Task,StartDate,EndDate (all the Employee Details are shown)

Now to highlight the details of particular who has logged in with the UserID as EmpID from all(i am carrying the Empid value as session id).

How to do it.

解决方案

Dear Friend,

This change of color can be achieved in the GridRowDataBound event. As the Data is being bound to the GridView, a GridView1_RowDataBound evetn is fired which binds each row with data in the DataTable or DataSet object bind to the Grid.

Here on the basis of your condition you can change the coor of different rows accordingly. For e.g.

protected void DrugGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType = DataControlRowType.DataRow)
   {
       //Check your condition here of checking the Employee ID from session
       If((UserID = Session["UserAuthentication"].ToString()))
       {
          e.Row.BackColor = Drawing.Color.Red // This will make row back color red
       }
    }
}



Here the Row containing the Employee ID from th DataTable Or DataSet can be checked against the Session Employee ID (from login as per your question). If the Condition matches then the Row color can be changed accordingly as required.

For your reference :- change-gridview-row-color-based-on-condition-in-c-sharp

Please don''t forget to mark this as your answer if it helps you out.

Regards

Varun Sareen


Hi,
Please have a look.. it will workout for you...

design one login.aspx page

]]>


Hi Friend,

Have a look to this code.its very simple

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
   {
       foreach (GridViewRow gvr in GridView1.Rows)
       {
           if (gvr.RowType == DataControlRowType.DataRow)
           {

//gvr.Cells[0].Text=where the empid is shown in gridview (change the cells[index] as per your //design)
//Session["userid"]=session value you are passing from loging page

               if (gvr.Cells[0].Text == Session["userid"].ToString())
               {
                   gvr.BackColor = System.Drawing.Color.Pink;


               }
           }


       }


   }


这篇关于Asp.net Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆