如何引用到FileUpload控件中的数据集 [英] how to reference to a fileupload control in a dataset

查看:206
本文介绍了如何引用到FileUpload控件中的数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的程序,当用户需要编辑的记录,presses编辑按钮,一个新窗口中打开了所有的字段和记录信息呈现到各自的领域给予用户编辑任何领域信息的选项他们需要。

In my program, when user wants to edit a record, and presses Edit button, a new window opens up with all the fields and record information is rendered into the respective fields giving user an option to edit any field information they require.

我添加了一个FileUpload控件到我的表单字段。但我不知道如何在我的新弹出窗口参考FileUpload控件..我不知道如果我解释我的问题很清楚与否,但我会尝试用以下code的帮助来解释它:

I have added a fileupload control to my webform fields. But I am not sure how to reference fileupload control on my new popped up window .. I am not sure if I am explaining my problem very clearly or not but I will try to explain it with the help of following code:

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();
         }
     }
}

基本上,当用户点击编辑,我的code是用来做什么,读在SQL Server,并从那里加载到一个新的弹出窗口中的相关记录在我的网页表单..把所有的信息在相关领域。
我在线阅读,从阅读SQL varbinary数据并绑定到Web窗体并不像调用文本数据一样简单。 (也许我错了,请纠正我,如果我)。我不是真的担心获取从SQL Server数据到网络表格,我担心的是指在新窗口中的上传控件,因为如果用户在弹出的窗口中FileUpload控件添加一个新的文件,如果它不是在引用我的code,我的程序忽略新上传的文件是在我的code一大缺陷。
问题是这条线code的:

Basically when user clicks edit, what my code does is, reads the relevant record in the sql server and loads it from there to a new popped up window in my webform .. puts all the information in the related fields. I read online that reading varbinary data from sql and binding it into the webform is not as simple as calling text data. (maybe I am wrong, please correct me if i am). I am not really worried about fetching data from sql server into the webform, I am worried about referring to the upload control in the new window because if user add a new file in fileupload control in the popped up window and if its not referenced in my code, my program ignores the new uploaded file which is a big flaw in my code. Problem is with this line of code:

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

我曾评论它为其他code运行。
我坚持了下来了整整一个星期。任何帮助将这么多的AP preciated。先谢谢了。

I have commented it out for other code to run. I am stuck with it for a whole week. Any help will be so much appreciated. Thanks in advance.

推荐答案

您不能绑定记录到文件上传控制,这种控制是上传文件
不可以
 下载。

You can't bind a record to a file upload control, this control is for uploading files not downloading.

看一看这个链接如何下载文件

Have a look at this link for how to download files.

上传控件应该被用来替换现有文件,当用户选择来取代它,即用户将上传新文件,并在你的业务逻辑需要使用现有的记录ID更新此记录。

The upload control should be used to replace the existing file,when the user chooses to replace it i.e. the user will upload a new file and in your business logic you need to update this record using the existing record ID.

在你的情况我会附件的ID绑定到一个隐藏字段在网格和先不谈上传控件。当记录更新检查文件上传控件有一个文件,然后使用附件的值更新附件。

In your case I'd bind the ID of the attachment to a hidden field in the grid and leave the upload control alone. When the record is updated check if the file upload control has a file and then using the value of the attachment update the attachment.

修改:从的这里我相信你会需要沿的线条添加一些:

Edit: From here I believe you would need to add something along the lines of:

FileUpload file = ((FileUpload)(GridView1.Rows[e.NewEditIndex].FindControl("myFileUploadControl")));

您需要给您的文件上传控件myFileUploadControl的ID(或任何你想要的)

You need to give your file upload control an ID of myFileUploadControl (or whatever you want)

问题也讨论使用在GridView一个FileUpload控件。

This question also discusses using a fileupload control in a gridview.

这篇关于如何引用到FileUpload控件中的数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆