需要在绑定到listview中的行之前获取数据值

时间:2015-04-25 23:06:29

标签: c# asp.net

我在Asp.Net(C#)中有一个 -keep class !android.support.v7.internal.view.menu.**, ** { *; } 对象,其中我还有 apply plugin: 'com.android.application' android { compileSdkVersion 22 buildToolsVersion "21.1.2" defaultConfig { applicationId "com.refresh.quickeer" minSdkVersion 16 targetSdkVersion 22 versionCode 1 versionName "1.0" multiDexEnabled true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } debug { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.1.1' compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.android.support:cardview-v7:22.1.0' compile 'com.android.support:recyclerview-v7:22.+' compile 'com.android.support:palette-v7:21.0.0' compile 'com.xgc1986.android:parallaxpagertransformer:1.0.3' compile project(':library') } 方法,该方法使用ListView填充。

在某些情况下,我希望能够在ListView 之前中将一行插入到绑定的当前记录中。即,在填充行时,我需要能够读取即将绑定的值,然后在将当前数据行添加到ListView_ItemDataBound()之前在流中插入“标题”行。

sqlDataSource事件的情况下,数据似乎已经绑定到控件上,因此添加的行实际上是一行ListView行,我无法做任何事情。

ItemDataBound

我对Asp.Net相对较新,并且来自经典的asp背景,所以也许我正在思考这一切都是错的。任何建议将不胜感激。

1 个答案:

答案 0 :(得分:0)

在您已经分配了数据源并调用listView.DataBind()之后,您应该在数据源中执行此操作,而不是这样做。假设它是DataTable

List<int> rowIndices = new List<int>();
for(int i = 0; i < dataTable.Rows.Count - 1; i++)
{
    int some_field = dataTable.Rows[i].Field<int>("some_field");
    if (some_field == 123)
        rowIndices.Add(i + rowIndices.Count); // indices will increases by count
}
foreach(int index in rowIndices)
{
    DataRow newRow = ....
    dataTable.Rows.InsertAt(newRow, index);
}

现在将此修改后的表分配为数据源并调用DataBind