如何在文件上载控件完成文件上载操作后禁用网格视图行

本文关键字:上载 文件 网格 视图 控件 操作 | 更新日期: 2023-09-27 17:58:48

我有一个网格视图,其中有三个字段。第一个是数据绑定字段,第二个是包含文本框控件的模板字段,第三个是再次包含FileUpload控件的模板域。

我想在文件上载控件完成文件上载操作时禁用网格视图行。

我的网格绑定代码是:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class gr4 : System.Web.UI.Page
{
    SqlConnection cn;
    SqlCommand cmd;
    SqlDataAdapter da;
    DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
    cn = new SqlConnection("Data Source=AMIR-PC''MOHEMMAD;Initial Catalog=CRM_InvestPlus;Integrated Security=True");
    string query = "Select Capacity from Dealer_License_Capacity where ID='D00001' and Software_ID='001' and Version_ID='1'";
    cn.Open();
    cmd = new SqlCommand(query,cn);
    da = new SqlDataAdapter(cmd);
    ds = new DataSet();
    da.Fill(ds);
    cn.Close();

    string query1 = "select  Price from Version_Master where Software_ID='001' and Version_ID='1'";
    cn.Open();
    cmd = new SqlCommand(query1, cn);
    da = new SqlDataAdapter(cmd);
    DataSet ds1 = new DataSet();
    da.Fill(ds1);
    cn.Close();

    string query2 = "select Software_Name from Software_Master where Software_ID='001'";
    cn.Open();
    cmd = new SqlCommand(query2, cn);
    da = new SqlDataAdapter(cmd);
    DataSet ds2 = new DataSet();
    da.Fill(ds2);
    cn.Close();
    DataTable dt = new DataTable();
   // dt.Columns.Add("Name", typeof(string));
    dt.Columns.Add("Software_Name", typeof(string));
    dt.Columns.Add("Price", typeof(string));
    int count = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
    for (int i = 0; i < count; i++)
    {
        DataRow dr = dt.NewRow();
     //   dr["Name"] = "aaa";
        dr["Software_Name"] = ds2.Tables[0].Rows[0][0].ToString();
        dr["Price"] = ds1.Tables[0].Rows[0][0].ToString();
        dt.Rows.Add(dr);
        if (i == 0)
            Response.Write(dr["Price"]);
    }
    GridView1.DataSource = dt;
    GridView1.DataBind();
    //GridView1.SelectedRow.Enabled = false;

  }
}

网格的源文件是:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
    <Columns>
        <asp:BoundField DataField="Software_Name" />
        <asp:TemplateField>
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("Price") %>'></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>

        <asp:TemplateField>
            <ItemTemplate>
                <asp:FileUpload ID="FileUpload1" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>

    </Columns>
    </asp:GridView>

数据是完美绑定的,但我想在文件上传控件完成操作后禁用gridview的选定行。

请帮助

提前谢谢。

如何在文件上载控件完成文件上载操作后禁用网格视图行

protected void GridView1_DataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
               e.Row.Enabled=false;//Check on the condition that uploaded is completed            
        }
    }