小编use*_*094的帖子

c# - 如何从List中获取值的总和?

我想从列表中获取值的总和.

例如:我在列表中有4个值1 2 3 4我想对这些值求和并在Label中显示它

码:

protected void btnCalculate_Click(object sender, EventArgs e)
{
    string monday;
    TextBox txtMonTot;
    List<string> monTotal = new List<string>();

    if (Application["mondayValues"] != null)
    {
        List<string> monValues = Application["mondayValues"] as List<string>;
        for (int i = 0; i <= gridActivity.Rows.Count - 1; i++)
        {
            GridViewRow row = gridActivity.Rows[i];
            txtMonTot = (TextBox)row.FindControl("txtMon");
            monday = monValues[i];
            monTotal.Add(monday);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?提前致谢

c# asp.net

21
推荐指数
3
解决办法
11万
查看次数

c# - 如何将时间戳转换为日期?

我从xml document获取时间戳.现在,我想将Timestamp转换为Date格式(13-May-13)

XmlNodeList cNodes = xncomment.SelectNodes("comment");
foreach (XmlNode node in cNodes)
{
    //I'm getting this "1372061224000" in comment-date
    string comment_date = node["creation-timestamp"].InnerText;
}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?提前致谢.

c# asp.net date

12
推荐指数
2
解决办法
4万
查看次数

如何在asp.net中单击按钮时动态添加控件?

我正在尝试动态添加控件

码:

AddVisaControl.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AddVisaControl.ascx.cs" EnableViewState="false" Inherits="Pyramid.AddVisaControl" %>
<%@ Register assembly="BasicFrame.WebControls.BasicDatePicker" namespace="BasicFrame.WebControls" tagprefix="BDP" %>
<div id="divreg" runat="server">
<table id="tbl" runat="server">
<tr>
  <td class="style8"> Visa Number:</td>
  <td class="style20"><asp:TextBox ID="txtUser" Width="160px" runat="server"/></td>
  <td class="style22"> Country Name:</td>
  <td class="style23">
<asp:DropDownList ID="dropCountry" Width="165px" runat="server">
</asp:DropDownList></td>
</tr>
 <tr>
 <td class="style22"> Type of Visa:</td>
 <td class="style23">
<asp:DropDownList ID="dropVisa" Width="165px" runat="server"> </asp:DropDownList></td>
<td class="style22"> Type of Entry:</td>
<td class="style23">
<asp:DropDownList ID="dropEntry" Width="165px" runat="server"> </asp:DropDownList></td>
</tr>
<tr>
<td class="style8">&nbsp; Expiry Date</td>
<td class="style20">
</td>
</tr> …
Run Code Online (Sandbox Code Playgroud)

c# asp.net

6
推荐指数
1
解决办法
2万
查看次数

c# - 未将对象引用设置为实例

我正试着从推特那里得到推文

但是我收到了一个错误

对象引用未设置为实例

码:

    public void Call_Tweet_Update()
    {
        var service = new TwitterService(Consumer_Key, Consumer_Secret);
        service.AuthenticateWith(Access_Token, AccessToken_Secret);

        var tweets = service.ListTweetsOnHomeTimeline(new ListTweetsOnHomeTimelineOptions { Count = 200 });
        string[] twt_id = new string[50];
        long id = 0;
        int i = 0;
        int increment = 0;
        string twtid;
        string screenname;

        foreach (var tweet in tweets)
        {
            if (tweet.InReplyToStatusId.ToString() != "")
            {
                if ((tweet.User.ScreenName == "IIPL_LTD") || (tweet.Text.StartsWith("@IIPL_LTD")))
                {
                    string replyid = tweet.InReplyToStatusId.ToString();

                    while (replyid != "")
                    {
                        if (i == 0)
                        {
                            twt_id[i] …
Run Code Online (Sandbox Code Playgroud)

c# asp.net twitter

5
推荐指数
1
解决办法
1105
查看次数

在asp.net中只能将一个ScriptManager实例添加到页面中

当我尝试添加用户控件时,我收到了此错误

Only one instance of a ScriptManager can be added to the page 
Run Code Online (Sandbox Code Playgroud)

码:

的.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VisaUserControl.ascx.cs" Inherits="Portal.VisaUserControl" %>
<%@ Register Assembly="BasicFrame.WebControls.BasicDatePicker" Namespace="BasicFrame.WebControls" TagPrefix="dp" %>
<asp:ScriptManager ID="scriptmanager1" runat="server"></asp:ScriptManager>
<div id="divreg" runat="server">
<table id="tbl" runat="server">
    <tr>
    <td>
        <asp:Label ID="lbl2" runat="server"></asp:Label>
    </td>
</tr>
<tr>
<td> Visa Number:</td>
<td><asp:TextBox ID="txtUser" Width="160px" runat="server"/></td>
<td> Country Name:</td>
<td><asp:DropDownList ID="dropCountry" Width="165px" runat="server"></asp:DropDownList></td>
</tr>
<tr>
<td> Type of Visa:</td>
<td><asp:DropDownList ID="dropVisa" Width="165px" runat="server" OnSelectedIndexChanged="dropVisa_SelectedIndexChanged"></asp:DropDownList></td>
<td> Type of Entry:</td>
<td><asp:DropDownList ID="dropEntry" Width="165px" runat="server"></asp:DropDownList></td>
</tr>
<tr> …
Run Code Online (Sandbox Code Playgroud)

c# asp.net ajax user-controls

5
推荐指数
1
解决办法
5万
查看次数

如何在XmlNodeList的foreach中使用反向?

我想从foreach中获取相反的数据

这里 XmlNodeList comments = d.SelectNodes("//comments/comment/creator");

我有4个值,我想将其反转

我已经写了这段代码

 public void commentM4(string pstId, string cmtId)
    {
        XmlDocument d = new XmlDocument();
        d.LoadXml(content);

        XmlNodeList comments = d.SelectNodes("//comments/comment/creator");
        foreach (XmlNode xncomment in  comments)
        {
            commentMemberId = xncomment["id"].InnerText;
            DbConnection.Open();
            DbCommand = new OleDbCommand("select count(response_id) from  mw_response where customer_id = '" + commentMemberId + "' AND post_id='" + pstId + "'", DbConnection);
            OleDbDataReader DbReader = DbCommand.ExecuteReader();

            while (DbReader.Read())
            {
                count = DbReader[0].ToString();
                cnt = Convert.ToInt32(count);
                if ((cnt == 0) && (comments1 != ""))
                {
                    DbCommand …
Run Code Online (Sandbox Code Playgroud)

c# asp.net foreach xml-parsing

2
推荐指数
1
解决办法
1479
查看次数

c# - 索引超出范围异常

我是.net开发的新手,当循环在下面的代码中得到错误时

指数超出范围.必须是非负数且小于集合的大小.

 public void postM()
    {
        for (int i = 0; i < listCustomer.Count; i++)
        {

            var grt = listCustomer[i];
            id = grt.UserId;

            //When the loops come second time

            for (int j = 0; j < listPost.Count; j++)
            {
                //Here I'm getting the above error
                var grt1 = listPost[i];
                postId = listPost[i].PostId;
                posts1 = listPost[i].Posts;
                postTime = listPost[i].PostTimeStamp;

                DbConnection.Open();
                DbCommand = new OleDbCommand("select count(*) from mw_post where post_id = '" + postId + "'", DbConnection);
                OleDbDataReader DbReader1 = DbCommand.ExecuteReader();
                while …
Run Code Online (Sandbox Code Playgroud)

c# asp.net for-loop

-2
推荐指数
1
解决办法
2616
查看次数

c# - 索引超出范围

我正试图从推特那里得到推文.

将所有数据存储到数据库中,然后将其传递给Siebel.

我收到一个错误:

指数超出范围

以下是代码:

 public void Call_Tweet_Update()
    {
        var service = new TwitterService(Consumer_Key, Consumer_Secret);
        service.AuthenticateWith(Access_Token, AccessToken_Secret);

        var tweets = service.ListTweetsOnHomeTimeline(new ListTweetsOnHomeTimelineOptions { Count = 200 });
        string[] twt_id = new string[50];
        long id = 0;
        int i = 0;
        int increment = 0;
        string twtid;
        string screenname;

        foreach (var tweet in tweets)
        {
            if (tweet.InReplyToStatusId.ToString() != "")
            {
                if ((tweet.User.ScreenName == "IIPL_LTD") || (tweet.Text.StartsWith("@IIPL_LTD")))
                {
   string replyid = tweet.InReplyToStatusId.ToString();

    while (replyid != "")
    {
        if (i == 0)
        { …
Run Code Online (Sandbox Code Playgroud)

c# asp.net

-6
推荐指数
1
解决办法
190
查看次数

标签 统计

asp.net ×8

c# ×8

ajax ×1

date ×1

for-loop ×1

foreach ×1

twitter ×1

user-controls ×1

xml-parsing ×1