0

我正在从 Javascript 调用代码隐藏方法并将该值传递到隐藏字段中,从该方法我需要调用另一个具有参数 IdataReader 的方法怎么办?

   page1.aspx  
   function changeCurrencyinternaluser()
        {
            curhf=document.getElementById('TableBuilder1_hf_currency');
            currencylit=document.getElementById('lit_currency');
            if (currencylit && curhf) 
                currencylit.innerHTML=curhf.value;                      
                curhfid=document.getElementById('TableBuilder1_hf_currencyid');
                currencyid=curhfid.value; 

                 document.getElementById('<%= h3plcurrid.ClientID %>').value = currencyid;   //deep
                 document.getElementById('<%= LinkButton2.ClientID %>').click();              
        }


   page1.aspx.cs
     protected void LinkButton2_Click(object sender, EventArgs e)
      {
        usercurrid = h3plcurrid.Value;  // hidden field
       //I need to call below method getsupplierNumber 

     }


    private Control getSupplierNumber(IDataReader dr)
     {
      //some code
     }
4

2 回答 2

1

一个典型的用法是:执行一条 SQL 命令,例如:

using(var conn = GetAnOpenConnection())
using(var cmd = conn.CreateCommand())
{
    cmd.CommandText = ...
    cmd.Parameters.Add(...);
    using(var reader = cmd.ExecuteReader())
    {
        var control = getSupplierNumber(reader);
    }
}

但是,虽然IDataReader 通常与数据库相关,但并非必须这样做。IDataReader您可以很容易地编写自定义实现。

于 2012-10-29T10:10:13.057 回答
0

以这种方式再传递一个值检查 usercurrid while (CarsInfoDataReader.Read()) {if (usercurrid==CarsInfoDataReader[index].tostring()) { ///if 满足填充值显示给用户 }

}

于 2012-10-29T10:10:37.967 回答