DropDownList dropdownlist1 =(DropDownList)GridView1.Rows [e.RowIndex] .FindControl(" dropdownlist1"); [英] DropDownList dropdownlist1 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("dropdownlist1");

查看:53
本文介绍了DropDownList dropdownlist1 =(DropDownList)GridView1.Rows [e.RowIndex] .FindControl(" dropdownlist1");的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的编码错误

任何人都可以帮忙更正此代码







i got error in this coding
any one can help to correct this code



private void Grid()
    {
        SqlConnection cn = new SqlConnection("Data Source=ANCYCHACKO-TOSH;Initial Catalog=tallysoftware;Integrated Security=True");

        SqlCommand cmd = new SqlCommand();
        DataTable dataTable;

        dataTable = new DataTable();

        cmd.Connection = cn;

        SqlDataAdapter da = new SqlDataAdapter("select * from Sheet1$ ", cn);

        System.Data.DataSet ds = new System.Data.DataSet();

        da.Fill(ds);

        if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        {

            GridView1.DataSource = ds.Tables[0];
            GridView1.DataSource = ds;
            GridView1.DataBind();
            cn.Close();
        }
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        Grid();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        e.Cancel = true;
        GridView1.EditIndex = -1;
        Grid();
    }


    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        Grid();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["tallysoftwareConnectionString4"].ConnectionString);
        SqlCommand cmd = new SqlCommand();
        cn.Open();
        GridViewRow row = GridView1.Rows[e.RowIndex];
        DropDownList dropdownlist1 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("dropdownlist1");
        TextBox txtEcollected = (TextBox)row.FindControl("txtEcollected");
        TextBox txtEplan = (TextBox)row.FindControl("txtEplan");
        TextBox txtEacoll = (TextBox)row.FindControl("txtEacoll");
        DropDownList dropdownlist2 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("dropdownlist2");
        TextBox txtEre = (TextBox)row.FindControl("txtEre");
        TextBox txtEdescrptn = (TextBox)row.FindControl("txtEdescrptn");
        //int Id = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
        string se_name = dropdownlist1.SelectedItem.Text;
        string collected_date = txtEcollected.Text;
        string amount_plan = txtEplan.Text;
        string amount_collected = txtEacoll.Text;
        string status_ar = dropdownlist2.SelectedItem.Text;
        string remark = txtEre.Text;
        string description = txtEdescrptn.Text;
        Label lblid = (Label)row.FindControl("Label3");
        // string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
        int id = Convert.ToInt32(lblid.Text);
        cmd.CommandText = "UPDATE Sheet1$ SET se_name='" + dropdownlist1.SelectedItem.Text + "' ,collected_date ='" + txtEcollected.Text + "',amount_plan ='" + txtEplan.Text + "',amount_collected ='" + txtEacoll.Text + "',status_ar ='" + dropdownlist2.SelectedItem.Text + "',remark='" + txtEre.Text + "',description='" + txtEdescrptn.Text + "' WHERE id=" + id + "";
        cmd.Connection = cn;
        cmd.ExecuteNonQuery();

        GridView1.EditIndex = -1;

        Grid();
        cn.Close();


    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["tallysoftwareConnectionString4"].ConnectionString);
        SqlCommand cmd = new SqlCommand();

        cmd.Connection = cn;
        cn.Open();
        GridViewRow row = GridView1.Rows[e.RowIndex];
        Label lblid = (Label)row.FindControl("Label3");
        // string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
        int id = Convert.ToInt32(lblid.Text);
        //int Id = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
        cmd.CommandText = "DELETE FROM Sheet1$ WHERE id='" + id + "' ";

        cmd.ExecuteNonQuery();
        cn.Close();
        Grid();
    }
}

推荐答案

,cn);

System.Data.DataSet ds = new System.Data.DataSet();

da.Fill(ds);

if (ds!= null && ds.Tables.Count > 0 && ds.Tables [ 0 ]。Rows.Count > 0
{

GridView1.DataSource = ds.Tables [ 0 ];
GridView1.DataSource = ds;
GridView1.DataBind();
cn.Close();
}
}
protected void GridView1_RowEditing( object sender,GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
Grid();
}
protected void GridView1_RowCancelingEdit( object sender,GridViewCancelEditEventArgs e)
{
e.Cancel = true ;
GridView1.EditIndex = -1;
Grid();
}


受保护 void GridView1_SelectedIndexChanged(< span class =code-keyword> object sender,EventArgs e)
{

}
protected void GridView1_PageIndexChanging( object sender,GridViewPageEventArgs e)
{
GridView1。 PageIndex = e.NewPageIndex;
Grid();
}
受保护 void GridView1_RowUpdating( object sender,GridViewUpdateEventArgs e)
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings [ tallysoftwareConnectionString4]。ConnectionString);
SqlCommand cmd = new SqlCommand();
cn.Open();
GridViewRow row = GridView1.Rows [e.RowIndex];
DropDownList dropdownlist1 =(DropDownList)GridView1.Rows [e.RowIndex] .FindControl( dropdownlist1 );
TextBox txtEcollected =(TextBox)row.FindControl( txtEcollected);
TextBox txtEplan =(TextBox)row.FindControl( txtEplan);
TextBox txtEacoll =(TextBox)row.FindControl( txtEacoll);
DropDownList dropdownlist2 =(DropDownList)GridView1.Rows [e.RowIndex] .FindControl( dropdownlist2);
TextBox txtEre =(TextBox)row.FindControl( txtEre);
TextBox txtEdescrptn =(TextBox)row.FindControl( txtEdescrptn);
// int Id = Int32.Parse(GridView1.DataKeys [e.RowIndex] .Value.ToString( ));
string se_name = dropdownlist1.SelectedItem.Text;
string gather_date = txtEcollected.Text;
string amount_plan = txtEplan.Text;
string amount_collected = txtEacoll.Text;
string status_ar = dropdownlist2.SelectedItem.Text;
string remark = txtEre.Text;
string description = txtEdescrptn.Text;
标签lblid =(标签)row.FindControl( Label3);
// string id = GridView1.DataKeys [e.RowIndex] .Value.ToString();
int id = Convert.ToInt32(lblid.Text);
cmd.CommandText = UPDATE Sheet1
", cn); System.Data.DataSet ds = new System.Data.DataSet(); da.Fill(ds); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { GridView1.DataSource = ds.Tables[0]; GridView1.DataSource = ds; GridView1.DataBind(); cn.Close(); } } protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; Grid(); } protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { e.Cancel = true; GridView1.EditIndex = -1; Grid(); } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; Grid(); } protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["tallysoftwareConnectionString4"].ConnectionString); SqlCommand cmd = new SqlCommand(); cn.Open(); GridViewRow row = GridView1.Rows[e.RowIndex]; DropDownList dropdownlist1 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("dropdownlist1"); TextBox txtEcollected = (TextBox)row.FindControl("txtEcollected"); TextBox txtEplan = (TextBox)row.FindControl("txtEplan"); TextBox txtEacoll = (TextBox)row.FindControl("txtEacoll"); DropDownList dropdownlist2 = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("dropdownlist2"); TextBox txtEre = (TextBox)row.FindControl("txtEre"); TextBox txtEdescrptn = (TextBox)row.FindControl("txtEdescrptn"); //int Id = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString()); string se_name = dropdownlist1.SelectedItem.Text; string collected_date = txtEcollected.Text; string amount_plan = txtEplan.Text; string amount_collected = txtEacoll.Text; string status_ar = dropdownlist2.SelectedItem.Text; string remark = txtEre.Text; string description = txtEdescrptn.Text; Label lblid = (Label)row.FindControl("Label3"); // string id = GridView1.DataKeys[e.RowIndex].Value.ToString(); int id = Convert.ToInt32(lblid.Text); cmd.CommandText = "UPDATE Sheet1


SET se_name =' + dropdownlist1.SelectedItem.Text + ',gather_date =' + txtEcollected。 Text + ',amount_plan =' + txtEplan.Text + ',amount_collected =' + txtEacoll.Text + ',status_ar =' + dropdownlist2.SelectedItem.Text + ' ,remark =' + txtEre.Text + ',description =' + txtEdescrptn.Text + 'WHERE id = + id + ;
cmd.Connection = cn;
cmd.ExecuteNonQuery();

GridView1.EditIndex = -1;

Grid();
cn.Close();


}
受保护 void GridView1_RowDeleting(< span class =code-keyword> object sender,GridViewDeleteEventArgs e)
{
SqlConnection cn = new SqlConnection(ConfigurationManager。 ConnectionStrings [ tallysoftwareConnectionString4]。ConnectionString);
SqlCommand cmd = new SqlCommand();

cmd.Connection = cn;
cn.Open();
GridViewRow row = GridView1.Rows [e.RowIndex];
标签lblid =(标签)row.FindControl( Label3);
// string id = GridView1.DataKeys [e.RowIndex] .Value.ToString();
int id = Convert.ToInt32(lblid.Text);
// int Id = Int32.Parse(GridView1.DataKeys [e.RowIndex] .Value.ToString( ));
cmd.CommandText = 从Sheet1删除
SET se_name='" + dropdownlist1.SelectedItem.Text + "' ,collected_date ='" + txtEcollected.Text + "',amount_plan ='" + txtEplan.Text + "',amount_collected ='" + txtEacoll.Text + "',status_ar ='" + dropdownlist2.SelectedItem.Text + "',remark='" + txtEre.Text + "',description='" + txtEdescrptn.Text + "' WHERE id=" + id + ""; cmd.Connection = cn; cmd.ExecuteNonQuery(); GridView1.EditIndex = -1; Grid(); cn.Close(); } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["tallysoftwareConnectionString4"].ConnectionString); SqlCommand cmd = new SqlCommand(); cmd.Connection = cn; cn.Open(); GridViewRow row = GridView1.Rows[e.RowIndex]; Label lblid = (Label)row.FindControl("Label3"); // string id = GridView1.DataKeys[e.RowIndex].Value.ToString(); int id = Convert.ToInt32(lblid.Text); //int Id = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString()); cmd.CommandText = "DELETE FROM Sheet1


WHERE id =' + id + ';

cmd.ExecuteNonQuery();
cn.Close();
Grid();
}
}
WHERE id='" + id + "' "; cmd.ExecuteNonQuery(); cn.Close(); Grid(); } }


这篇关于DropDownList dropdownlist1 =(DropDownList)GridView1.Rows [e.RowIndex] .FindControl(&quot; dropdownlist1&quot;);的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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