在行文本上更改gridview行的前景颜色

时间:2015-05-26 07:55:43

标签: c# asp.net gridview rows

有一行"正确"我的数据库中的文字。但是if条件永远不会成立。

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblremark = (Label)e.Row.FindControl("lblremark");
            if (lblremark.Text == "Correct")
            {
                e.Row.ForeColor = System.Drawing.Color.Black;
                e.Row.BackColor = System.Drawing.Color.Cyan;
            }
            else
            {
                e.Row.ForeColor = System.Drawing.Color.Black;
                e.Row.BackColor = System.Drawing.Color.Orange;
            }
        }   
    }

2 个答案:

答案 0 :(得分:0)

如果您正确找到标签,请尝试此操作

if (lblremark.Text.Trim().ToLower().Equals("correct"))

答案 1 :(得分:0)

注意:这只是我的头顶

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.AsyncTask;
import android.os.CountDownTimer;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

public class IncomingCall extends BroadcastReceiver {
private String firstname;
private String lastname;
private String username;
public void onReceive (Context context, Intent intent) {
// TODO Auto-generated method stub

    new AsyncTaskParseJson (context);

    Toast.makeText(context, "Calling ", Toast.LENGTH_LONG).show();  
 new AsyncTaskParseJson().execute();
  }


    class AsyncTaskParseJson extends AsyncTask<String, String, String> {
    AsyncTaskParseJson (Context context){

    }
    final String TAG = "AsyncTaskParseJson.java";

    // set your json string url here
    String yourJsonStringUrl =     "http://demo.codeofaninja.com/tutorials/json-example-with-php/index.php";

    // contacts JSONArray
    JSONArray dataJsonArr = null;

    @Override
    protected void onPreExecute() {}

    @Override

    protected String doInBackground(String... arg0) {

        try {

            // instantiate our json parser
            JsonParser jParser = new JsonParser();

            // get json string from url
            JSONObject json = jParser.getJSONFromUrl(yourJsonStringUrl);

            // get the array of users
            dataJsonArr = json.getJSONArray("Users");

            // loop through all users
           // for (int i = 0; i < dataJsonArr.length(); i++) {

                JSONObject c = dataJsonArr.getJSONObject(0);

                // Storing each json item in variable
                firstname = c.getString("firstname");
                lastname = c.getString("lastname");
                username = c.getString("username");

                // show the values in our logcat
                Log.e(TAG, "firstname: " + firstname 
                        + ", lastname: " + lastname
                        + ", username: " + username);

           // }

        } catch (JSONException e) {
            e.printStackTrace();
        }


        return null;
    }

    protected void onPostExecute(String strFromDoInBg) {


         Log.e("TAG1", "firstname: " + firstname 
                 + ", lastname: " + lastname
                 + ", username: " + username);
         title="hii";
         subject="subject";

         notifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notifyObj = new Notification(R.drawable.ic_launcher,
                "Notification message!", System.currentTimeMillis());
        PendingIntent i = PendingIntent.getActivity(context, 0, new Intent(
                context, NotifyMessage.class), 0);
        notifyObj.setLatestEventInfo(context, title,subject, i);
        notifyObj.number = ++count;
        notifyObj.defaults |= Notification.DEFAULT_VIBRATE;
        notifyObj.defaults |= Notification.DEFAULT_SOUND;
        notifyObj.flags |= Notification.FLAG_AUTO_CANCEL;
        notifyMgr.notify(NOTIFY_ME_ID, notifyObj);

        }
      }

       }