本文介绍了访问DataReader中的特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据读取器,用于在JS轮播中显示游戏周的列表.

I have a datareader to display a list of gameweeks in a js carousel.

我需要能够添加一个if语句来更改当前游戏周的div类.

I need to be able to add an if statement to change the div class of the current gameweek.

这是我当前的代码:

if (dReader.HasRows) {
    while (dReader.Read()) {
        gameweekList.Text += "<div class=\"item\"><h4>Gameweek " +
            (dReader["gameweekID"].ToString()) + "</h4></div>";
    }
} else {
    gameweekList.Text = "Error Finding Gameweeks";
}
dReader.Close();
conn.Close();

实际上,我想添加 if(dreader [1]),然后添加多余的位,这怎么可能?

In effect I want to add if(dreader[1]) then add the extra bit, how is this possible?

推荐答案

如何...

if (dReader.HasRows) {
    while (dReader.Read()) {

        if ( dReader["gameweekID"].ToString() == currentWeekId )
        {
            gameweekList.Text += "<div class=\"somethingSpecial\"><h4>Gameweek " +
            (dReader["gameweekID"].ToString()) + "</h4></div>";
        }
        else
        {
            gameweekList.Text += "<div class=\"item\"><h4>Gameweek " +
            (dReader["gameweekID"].ToString()) + "</h4></div>";
        }
    }
} else {
    gameweekList.Text = "Error Finding Gameweeks";
}
dReader.Close();
conn.Close();

这篇关于访问DataReader中的特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 10:41