我希望获得服务器端div的'display'css值!
以下代码不起作用:
if (div.Style["display"] == "none")
{
div.Style.Add("display", "table-row");
}
我怎样才能在c#中获得该值?
提前致谢
答案 0 :(得分:1)
你不能这样做,但我猜你正在应用一些逻辑来做一些事情,如果你的div可见或不显示(dispay:none或none)。如果是这样的话,为什么不使用html输入元素并根据需要切换其值?
答案 1 :(得分:1)
更好的解决方案:
<强> HTML 强>
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;
import net.sqlcipher.database.SQLiteDatabase;
import java.io.File;
public class DatabaseHelper extends SQLiteAssetHelper {
public DatabaseHelper(Context context, String dbName) {
super(context, dbName, null, 1);
}
//Command Out
/* public void InitializeSQLCipher(File databaseFile, String dbPass, String tableName) {
databaseFile.mkdirs();
databaseFile.delete();
SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(databaseFile, dbPass, null);
database.execSQL("create table " + tableName + "( ID INTEGER PRIMARY KEY AUTOINCREMENT, columnOne TEXT, columnTwo TEXT)");
database.close();
}*/
public void FillSQLCipher(File databaseFile, String dbPass, String tableName, String columnOne, String columnTwo, String values) {
SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(databaseFile, dbPass, null);
ContentValues cValues = new ContentValues();
cValues.put(columnOne, values);
cValues.put(columnTwo, values);
database.insert(tableName, null, cValues);
database.close();
}
public void getDataFromTable(File databaseFile, String dbPass, String tableName) {
try {
SQLiteDatabase enDatabase = SQLiteDatabase.openOrCreateDatabase(databaseFile, dbPass, null);
Cursor cursor = enDatabase.rawQuery("select * from " + tableName, null);
if (cursor.moveToFirst()) {
do {
for (int i = 0; i < cursor.getColumnCount(); i++) {
String neu = cursor.getString(i);
Log.d("Data: ", neu + "");
}
} while (cursor.moveToNext());
cursor.close();
enDatabase.close();
}
cursor.close();
enDatabase.close();
}catch (Exception e){
Log.d(tableName, "can not read the table!");
}
}
public void cleanData(File databaseFile, String dbPass, String tableName) {
SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(databaseFile, dbPass, null);
database.execSQL("delete from " +tableName);
database.close();
}
}
<强> C#强>
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import net.sqlcipher.database.SQLiteDatabase;
import java.io.File;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SQLiteDatabase.loadLibs(this);
Date now = new Date();
Calendar calendar = Calendar.getInstance();
calendar.getTimeInMillis();
//time now
Log.d("** Zeit jetzt: ", String.valueOf(now));
Log.d("** Milisekunden: ", String.valueOf(calendar.getTimeInMillis()));
***************************************\n");
Log.d("** verschlüsselte", "Datenbank:\n");
//Fill the table in the encrypted database
DatabaseHelper enDBHelper = new EncryptedDatabaseHelper(this, "encryptedDB.db");
File databaseFile = getDatabasePath("encryptedDB.db");
enDBHelper.InitializeSQLCipher(databaseFile, "abc123", "encryptedTableOne");
for (int i = 0; i < 21; i++) {
int randomValue = new Random().nextInt();
enDBHelper.FillSQLCipher(databaseFile, "abc123", "encryptedTableOne", "ColumnOne", "ColumnTwo", String.valueOf(randomValue));
}
//time now
now = new Date();
calendar = Calendar.getInstance();
Log.d("** Zeit jetzt: ", String.valueOf(now));
Log.d("** Milisekunden: ", String.valueOf(calendar.getTimeInMillis()));
Log.d("\n", " daten aus der verschlüsselten Datenbank ***************************************\n");
//read the table from encrypted database!
enDBHelper.getDataFromTable(databaseFile, "abc123", "encryptedTableOne");
/* enDBHelper.cleanData(databaseFile, "abc123", "encryptedTableOne");*/
Log.d("\n*******************", "\n");
now = new Date();
calendar = Calendar.getInstance();
Log.d("** Zeit jetzt: ", String.valueOf(now));
Log.d("** Milisekunden: ", String.valueOf(calendar.getTimeInMillis()));
Log.d("\n", " und hier ist Ende ***************************************\n");
}
}
答案 2 :(得分:0)
您无法在服务器端执行您要执行的操作。 Style属性仅适用于内联样式。考虑客户端JavaScript。
<div id="div" runat="server" style="display: none;">Foo</div>
答案 3 :(得分:0)
div.Attributes [“style”]。添加(“display”,“table-row”)
使用此:
if (div.Attributes["style"].ToString().Contains("display:none;"))
{ div.Attributes.Add("style", "display:table-row"); }
或尝试
div.Attributes["CLASS"].ToString().Contains("CLASS_NAME")