小编Ami*_*ban的帖子

如何在ASP.NET C#中使用foreach获取CheckBoxList中所选项的值?

我有一个像这样的CheckBoxList:

<asp:CheckBoxList ID="CBLGold" runat="server" CssClass="cbl">
    <asp:ListItem Value="TGJU"> TG </asp:ListItem>
    <asp:ListItem Value="GOLDOZ"> Gold </asp:ListItem>
    <asp:ListItem Value="SILVEROZ"> Silver </asp:ListItem>
    <asp:ListItem Value="NERKH"> NE </asp:ListItem>
    <asp:ListItem Value="TALA"> Tala </asp:ListItem>
    <asp:ListItem Value="YARAN"> Sekeh </asp:ListItem>
</asp:CheckBoxList>
Run Code Online (Sandbox Code Playgroud)

现在我想使用foreach从此CheckBoxList获取所选项的值,并将值放入列表中.

注意:我希望代码简短.

c# asp.net foreach list checkboxlist

70
推荐指数
3
解决办法
29万
查看次数

如何使用文化将变量中的波斯数字转换为英文数字?

我想更改保存在变量中的波斯数字,如下所示:

string Value="???????"; 
Run Code Online (Sandbox Code Playgroud)

string Value="1036751";
Run Code Online (Sandbox Code Playgroud)

我怎样才能使用像文化信息这样简单的方法来做到这一点?

我的示例代码是:

List<string> NERKHCOlist = new List<string>();
NERKHCOlist = ScrappingFunction(NERKHCO, NERKHCOlist);
int NERKHCO_Price = int.Parse(NERKHCOlist[0]);//NERKHCOlist[0]=??????? 
Run Code Online (Sandbox Code Playgroud)

<=所以它不能解析为int
这是在我的函数中,它返回列表项中包含波斯数字的列表

protected List<string> ScrappingFunction(string SiteAddress, List<string> NodesList)
{    
    string Price = "null";
    List<string> Targets = new List<string>();
    foreach (var path in NodesList)
    {
        HtmlNode node = document.DocumentNode.SelectSingleNode(path.ToString());//recognizing Target Node
        Price = node.InnerHtml;//put text of target node in variable(PERSIAN DIGITS)
        Targets.Add(Price);
    }
    return Targets;
}
Run Code Online (Sandbox Code Playgroud)

.net c# cultureinfo persian string-parsing

27
推荐指数
6
解决办法
8553
查看次数

如何将Class作为方法的参数传递?

我有两个班:

Class Gold;
Class Functions;
Run Code Online (Sandbox Code Playgroud)

有一种方法ClassGet在类Functions,其具有2个参数.我想将类Gold作为参数发送给我在课堂上的一个方法Functions.这怎么可能?

例如:

public void ClassGet(class MyClassName, string blabla)
{
    MyClassName NewInstance = new MyClassName();
}
Run Code Online (Sandbox Code Playgroud)

注意:我想将MyClassName字符串参数发送到我的方法.

c# methods class function parameter-passing

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

如何在C#中返回Struct From Function?

我定义了一个像这样的结构:

 public struct Averages
    {
        public decimal Sell_GoldOunce = 0;
        public decimal Buy_GoldOunce = 0;
        public decimal Sell_SilverOunce = 0;
        public decimal Buy_SilverOunce = 0;
        public int Sell_Mazene = 0;
        public int Buy_Mazene = 0;
        public int Sell_Gram_18 = 0;
        public int Buy_Gram_18 = 0;
        public int Sell_Gram_24 = 0;
        public int Buy_Gram_24 = 0;
    };
Run Code Online (Sandbox Code Playgroud)

现在我想在我的功能中使用它然后返回它

    public (?) AssignValues()// I WANT TO KNOW WHAT SHOULD I PUT INSTITE OF (?)
    {
        Averages GoldValues;
        GoldValues.Sell_GoldOunce = somevalue;
        GoldValues.Buy_GoldOunce = somevalue; …
Run Code Online (Sandbox Code Playgroud)

c# methods struct function return-value

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

过程或函数'x'需要参数'@y',这是未提供的.在c#上有错误?

首先,我知道这些问题是重复但是请注意这个期望.这是我的C#代码,它将错误提升为:

过程或函数'aaa'需要参数'@bbb',这是未提供的.

if (Dt.Rows.Count > 0)
{
    Cmd = new SqlCommand();
    Cmd.CommandText = ("[dbo].[aaa]");
    Cmd.CommandType = CommandType.StoredProcedure;
    Cmd.Parameters.Add("@bbb", SqlDbType.Int).Value = 1;
    Cmd.Parameters.Add("@LettType", SqlDbType.VarChar, 3).Value = LetterType;
    Cmd.Parameters.Add("@IsTajamo", SqlDbType.Char, 1).Value = 1;
    Da = new SqlDataAdapter(Cmd.CommandText, Con);
    Dt.Clear();
    /*Line72:*/    
    Da.Fill(Dt);
}
Run Code Online (Sandbox Code Playgroud)

从技术上讲,我找不到错误在哪里.我通过了所有参数.当我在MS-SQL中单独执行我的存储过程时,它可以正常使用这些值.

你可以请专家帮我解决这个问题吗?注意:这里是存储过程:

   ALTER PROCEDURE [dbo].[aaa] (@bbb Int , @LettType CHAR(3) , @IsTajamo CHAR(1))

AS
BEGIN

select 1


END
Run Code Online (Sandbox Code Playgroud)

注意:(可能这可以帮助,这是我的堆栈跟踪):

在System.Data.SqlClient.SqlConnection.OnError(SqlException异常,布尔breakConnection,动作1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1个wrapCloseInAction)在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj,布尔callerHasConnectionLock,布尔asyncClose)在System.Data.SqlClient.TdsParser.在System.Data.SqlClient的System.Data.SqlClient.SqlDataReader.get_MetaData()处的System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()处的TryRun(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj,Boolean&dataReady) System.Data.SqlClient.SqlCommand.RunExecuteReaderTds中的.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior runBehavior,String resetOptionsString,Boolean isInternal,Boolean …

c# sql-server asp.net stored-procedures sqldataadapter

0
推荐指数
1
解决办法
1048
查看次数