本文介绍了将文本框值从aspc.cs文件传递到用户控件(ascx.cs)文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我必须创建一个带有选定日期的excel文件。为此,我需要将文本框日期值从aspx.cs文件传递到用户控件(ascx.cs)文件。首先,我从aspx页面获取文本框值到aspx.cs文件。



POSDetailReports.aspx.cs

Hi friends,

I have to create a excel file with a selected date. For that I need to pass a textbox date value from a aspx.cs file to a User Control(ascx.cs) file. First I get the textbox value from the aspx page to the aspx.cs file.

POSDetailReports.aspx.cs

public string ButtonSelectedDate()
        {
         
                return this.selectDateDisplayTextBox.Text;
          
        }









然后我将此方法调用到ascx.cs文件



DailySalesFigureUserControl.ascx.cs





Then I call this method to the ascx.cs file

DailySalesFigureUserControl.ascx.cs

protected void ExportActionButton_Click(object sender, EventArgs e)
       {
           try
           {
               List<string> header = new List<string>();
               Dictionary<int, List<string>> body = new Dictionary<int, List<string>>();
               List<string> footer = new List<string>();

               DailySalesFigureModelResponseDto dailySales = new DailySalesFigureModelResponseDto();
               Type type = dailySales.GetType();
               PropertyInfo[] propertyInfoArray = type.GetProperties();
               int count = 0;

               foreach (PropertyInfo propertyInfo in propertyInfoArray)
               {
                   header.Add(propertyInfo.Name);
               }

               foreach (DailySalesFigureModelResponseDto dailySalesResponse in this.DataSource)
               {
                   List<string> bodyRow = new List<string>();

                   foreach (PropertyInfo propertyInfo in propertyInfoArray)
                   {
                       string propertyValue = string.Empty;

                       object value = propertyInfo.GetValue(dailySalesResponse, null);

                       if (value != null)
                       {
                           propertyValue = value.ToString();
                       }

                       bodyRow.Add(propertyValue);
                   }

                   body.Add(count, bodyRow);
                   count++;
               }

               ExportableDataContent exportableDataContent = new ExportableDataContent(header, body, footer);

               TabularContent tabularContent = new TabularContent();
               tabularContent = exportableDataContent.ToTabularFormat();

               DefaultExporter exporte = new DefaultExporter();

               exporte.Open(string.Empty);

               ExportLocation exportLocation = new ExportLocation("A", "2", "Sheet1");
               exporte.WriteContent(tabularContent, exportLocation);

               string tempFolderPath = @"D:\";  ////Path.GetTempPath();

               string fileName = this.posDetailReports.ButtonSelectedDate() + ".xlsx";

               string excelFilePath = tempFolderPath + fileName;

               if (File.Exists(excelFilePath))
               {
                   File.Delete(excelFilePath);
               }

               exporte.Save(excelFilePath, ExportFormat.Excel);

           }
           catch (Exception ex)
           {

           }
       }







方法返回null。




The method is returning null.

string fileName = this.posDetailReports.ButtonSelectedDate() + ".xlsx";





任何人都可以帮我吗?





提前致谢



Can anyone help me on this??


Thanks in advance

推荐答案

public string FileName
{
    get
    {
        return fileName;
    }
    set
    {
        fileName = value;
    }
}



在您的POSDetailReports.aspx.cs中,使用此代码


In your POSDetailReports.aspx.cs, use this code

usrControl.FileName = ButtonSelectedDate();



这篇关于将文本框值从aspc.cs文件传递到用户控件(ascx.cs)文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 03:07