【问题标题】:How to refer to a fileupload control opened in a new window through code如何通过代码引用在新窗口中打开的fileupload控件
【发布时间】:2013-09-18 04:52:27
【问题描述】:

我已将行编辑功能带到我程序中的新窗口。请先看看我的代码:

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
 lblSet.Text = GridView1.Rows[e.NewEditIndex].Cells[2].Text;
 MultiView1.SetActiveView(vRecord);

 btnSave.Visible = false;
 btnBacktoHome.Visible = true;
 //this.lblMedium.Text = GridView1.Rows[e.NewEditIndex].Cells[1].Text;


 using (SqlConnection con = new SqlConnection("Data Source=MEHDI-PC\\SQLEXPRESS;Initial Catalog=PIMS;Integrated Security=True"))
 {
     using (SqlCommand cmd = new SqlCommand())
     {
         String sql = "select [DocumentID],[Ref],[Subject],[Src],[Dst],[Medium],[Date_Printed],[Date_Received],[Document_Type],[Action_Required],[Due_Date],[Actual_Date],[Content],[Tag],[Issue_No],[Attachment],[Notes],[Assigned_To],[Reply_Ref],[Priority],[Status],[Response],[Physical_File_No],[Physical_Rack_Location] from dbo.Documents1 where [DocumentId]=N'" + GridView1.Rows[e.NewEditIndex].Cells[2].Text + "'";
         cmd.Connection = con;
         cmd.CommandText = sql;
         con.Open();

         //SqlDataAdapter da = new SqlDataAdapter(sql,con);
         //DataTable dt = new DataTable();
         DataSet ds = new DataSet();
         using (SqlDataAdapter adp = new SqlDataAdapter(cmd))
         {
             adp.Fill(ds);
         }


         this.txtRef.Text = ds.Tables[0].Rows[0][1].ToString();
         this.txtSubject.Text = ds.Tables[0].Rows[0][2].ToString();
         this.ddlSource.Text = ds.Tables[0].Rows[0][3].ToString();
         this.ddlDestination.Text = ds.Tables[0].Rows[0][4].ToString();
         this.ddlMedium.Text = ds.Tables[0].Rows[0][5].ToString();
         this.txtDatePrinted.Text = ds.Tables[0].Rows[0][6].ToString();
         this.txtDateReceived.Text = ds.Tables[0].Rows[0][7].ToString();
         this.ddlDocumentType.Text = ds.Tables[0].Rows[0][8].ToString();
         this.cbxAction.Checked = ds.Tables[0].Rows[0][9].Equals(cbxAction.Checked);
         this.txtDueDate.Text = ds.Tables[0].Rows[0][10].ToString();
         this.txtActualDate.Text = ds.Tables[0].Rows[0][11].ToString();
         this.txtContent.Text = ds.Tables[0].Rows[0][12].ToString();
         this.txtTag.Text = ds.Tables[0].Rows[0][13].ToString();
         this.txtIssue.Text = ds.Tables[0].Rows[0][14].ToString();

         //this.fileupload1 = ds.Tables[0].Rows[0][15] ;

         this.txtNotes.Text = ds.Tables[0].Rows[0][16].ToString();
         this.ddlAssignedTo.Text = ds.Tables[0].Rows[0][17].ToString();
         this.txtReplyRef.Text = ds.Tables[0].Rows[0][18].ToString();
         this.ddlPriority.Text = ds.Tables[0].Rows[0][19].ToString();
         this.ddlStatus.Text = ds.Tables[0].Rows[0][20].ToString();
         this.ddlResponse.Text = ds.Tables[0].Rows[0][21].ToString();
         this.txtPhysicalFileNo.Text = ds.Tables[0].Rows[0][22].ToString();
         this.txtPhysicalRackLocation.Text = ds.Tables[0].Rows[0][23].ToString();

         if (con != null)
         {
             con.Close();
         }
         btnUpdate.Visible = true;
         btnSearch.Visible = false;
         BindGrid();
     }
 }

}

当 RowEditing 事件触发时,会在我的程序中打开一个新页面,其中会呈现记录的所有字段。用户编辑他们想要的任何字段,当他们按下此页面底部给出的更新按钮时,Rowupdating 事件会触发。

现在正如代码所示,我指的是一个文本框,例如:

this.txtRef.Text = ds.Tables[0].Rows[0][1].ToString();

我实际上被文件上传控制所困扰。我不知道如何在我的新窗口中引用它。也就是说,

//this.fileupload1 = ds.Tables[0].Rows[0][15] ;

我已经注释掉了这行代码,以便其他代码能够顺利运行。我已经在线阅读了如何在网格视图中使用文件上传,但我遇到的所有信息都是关于在 GridView 中实现的 RowEditing 设计,而不是在新窗口中。任何帮助都感激不尽。亲切的问候。

【问题讨论】:

    标签: c# asp.net gridview


    【解决方案1】:

    您不能这样分配文件。 更好的选择是,在编辑视图中,在标签中显示文件名。 然后在其下方提供文件上传控件以上传文件,在上传文件时替换旧文件并更新标签名称。

    【讨论】:

    • 文件上传控件所做的只是“提供文件的'路径'”。现在首先,为什么不能通过代码引用文件上传控件..当可以引用文本框时(即this.txtRef.Text = ds.Tables[0].Rows[0][1].ToString();)其次,如果文件上传所做的只是传递文件的“路径”,那么为什么不能在行编辑模式。我相信这是可能的,但仅限于那些知道如何去做的人。
    • 好吧。我现在明白了。我更改了设计,添加了一个模板字段和一个项目字段 (LABEL),在该项目字段的 editItem 模式中,我添加了一个“FileUpload”.. 并尝试以这种方式访问​​ fileupload.. 所有代码都可以编译但没有产生输出。如果您有时间和知识,我应该将代码粘贴给您吗?谢谢
    • @RehanMehdi:好吧。会尝试
    • 我应该给你我项目的链接吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-06
    • 2019-04-10
    • 1970-01-01
    • 1970-01-01
    • 2020-11-08
    • 1970-01-01
    相关资源
    最近更新 更多