需要帮助显示内部选框数据

发布于 2024-07-16 21:43:16 字数 1978 浏览 6 评论 0原文

我想在我的银行应用程序中的字幕标记内显示新闻,但它没有发生。请有人帮助我,我的代码中有什么错误。这是我的代码:

<marquee bgcolor="silver" direction="left" id="marq1" runat="server" behavior="scroll" scrolldelay="80" style="height: 19px" width="565">
<% 
   String se = Session["countnews"].ToString();
   for (int i = 0; i < int.Parse("" +se); i++)
   { %>
       <strong><%Response.Write("&nbsp;&nbsp;" + Session["news"+i] + "&nbsp;&nbsp;"); %></strong>
<% } %>
</marquee>

public class News
{
    DataSet ds = new DataSet("Bank");
    SqlConnection conn;
    String check;
    SqlDataAdapter sda;
    int i;
    public string News_Name;
    public int Count_News;
public int newsticker()
    {
        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["BankingTransaction"].ConnectionString.ToString());
        check = "Select NewsTitle from News where NewsStatus = 'A'";
        sda = new SqlDataAdapter(check, conn);
        sda.Fill(ds, "News");
        if (ds.Tables[0].Rows.Count > 0)
        {
            for (i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                News_Name =i+ ds.Tables[0].Rows[i].ItemArray[0].ToString();
            }
            Count_News = ds.Tables[0].Rows.Count;        }
        else
        {
            News_Name =0+ "Welcome to WestSide Bank Online Web site!";
            Count_News = 1;
        }
        return int.Parse(Count_News.ToString());       
    }

protected void Page_Load(object sender, EventArgs e)
    {
        News obj = new News();
        try
        {
            obj.newsticker();
            Session["news"] = obj.News_Name.ToString();
            Session["countnews"] = obj.Count_News.ToString();       
        }
        catch (SqlException ex)
        {
            Response.Write("Error in login" + ex.Message);
            Response.Redirect("Default.aspx");
        }
        finally
        {
            obj = null;
        } 
    }

I want to display news inside the marquee markup in my banking application but its not happening.Please somebody help me what is the error in my code.Here is my code:

<marquee bgcolor="silver" direction="left" id="marq1" runat="server" behavior="scroll" scrolldelay="80" style="height: 19px" width="565">
<% 
   String se = Session["countnews"].ToString();
   for (int i = 0; i < int.Parse("" +se); i++)
   { %>
       <strong><%Response.Write("  " + Session["news"+i] + "  "); %></strong>
<% } %>
</marquee>

public class News
{
    DataSet ds = new DataSet("Bank");
    SqlConnection conn;
    String check;
    SqlDataAdapter sda;
    int i;
    public string News_Name;
    public int Count_News;
public int newsticker()
    {
        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["BankingTransaction"].ConnectionString.ToString());
        check = "Select NewsTitle from News where NewsStatus = 'A'";
        sda = new SqlDataAdapter(check, conn);
        sda.Fill(ds, "News");
        if (ds.Tables[0].Rows.Count > 0)
        {
            for (i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                News_Name =i+ ds.Tables[0].Rows[i].ItemArray[0].ToString();
            }
            Count_News = ds.Tables[0].Rows.Count;        }
        else
        {
            News_Name =0+ "Welcome to WestSide Bank Online Web site!";
            Count_News = 1;
        }
        return int.Parse(Count_News.ToString());       
    }

protected void Page_Load(object sender, EventArgs e)
    {
        News obj = new News();
        try
        {
            obj.newsticker();
            Session["news"] = obj.News_Name.ToString();
            Session["countnews"] = obj.Count_News.ToString();       
        }
        catch (SqlException ex)
        {
            Response.Write("Error in login" + ex.Message);
            Response.Redirect("Default.aspx");
        }
        finally
        {
            obj = null;
        } 
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花之痕靓丽 2024-07-23 21:43:16

会议["新闻"+i]

但是您没有将任何称为“新闻”加整数的内容放入会话范围中。 您正在迭代数据集并将每个标题(神秘地带有整数前缀)作为“News_Name”属性存储在单个新闻对象中。 每次写入“News_Name”都会覆盖前一个,因此只有最后一个标题会存储在 Session[“news”] 的末尾。

无论如何,会话对于存储每页数据来说都是一个麻烦的地方:会话用于在多个页面加载过程中持续存在的数据,并且如果用户同时加载两个页面,则可能会产生干扰。

另外,您正在 Response.Write() 处理一个字符串,而没有在输出时对其进行 HTMLEncode() 处理,如果新闻标题可能有 ' <' 其中的人物。 我不太清楚为什么你要采用“newscount”整数,将其转换为字符串,再次将其转换为字符串,再次将其转换为字符串,最后将其解析回整数。 (?)

总的来说,这似乎是经典 ASP 和代码隐藏技术的令人不舒服的混合。 在我看来,应该可以使用类似这样的东西来写得更简单:

<asp:Repeater DataSourceID="TickerSource" runat="server">
    <ItemTemplate><strong>
        <%# Eval("NewsTitle") %>
    </strong></ItemTemplate>
</asp:Repeater>

<asp:SqlDataSource ID="TickerSource" runat="server"
    SelectCommand="SELECT NewsTitle FROM News WHERE NewsStatus='A'"
    ConnectionString="<%$ ConnectionStrings:BankingTransaction %>"
/>

[免责声明:我一生中从未真正编写过一行 ASP.NET,所以这可能无法按原样工作。 欢迎更多精通 .NET 的用户进行编辑。]

Session["news"+i]

But you're not putting anything called ‘news’-plus-an-integer into Session scope. You're iterating over a dataset and storing each title (mysteriously prefixed by an integer) as the ‘News_Name’ property in a single News object. Each write to ‘News_Name’ overwrites the previous one, so only the last title gets stored at the end in Session["news"].

In any case, Session is a troublesome place to be storing per-page data: Session is for data that persists over multiple page loads, and can interfere if the user is loading two pages at once.

Also, you're Response.Write()ing a string without HTMLEncode()ing it on the way out, which is bad news for security (especially on a ‘banking site’!) if the title of the news might have a ‘<’ character in it. And I'm not quite sure why you're taking the ‘newscount’ integer, converting it to string, converting it to string again, converting it to string again then finally parsing it back to an integer. (?)

In general this seems like an uncomfortable mix of classic-ASP and codebehind techniques. It seems to me it should be possible to write this a whole lot simpler using something like:

<asp:Repeater DataSourceID="TickerSource" runat="server">
    <ItemTemplate><strong>
        <%# Eval("NewsTitle") %>
    </strong></ItemTemplate>
</asp:Repeater>

<asp:SqlDataSource ID="TickerSource" runat="server"
    SelectCommand="SELECT NewsTitle FROM News WHERE NewsStatus='A'"
    ConnectionString="<%$ ConnectionStrings:BankingTransaction %>"
/>

[Disclaimer: I've never actually written a line of ASP.NET in my life, so this may not work as-is. Edits from more .NET-savvy users welcome.]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文