如何在rowediting事件中启用嵌套在gridview内的文本框? [英] How can I enable textbox nested inside gridview in rowediting event ?

查看:70
本文介绍了如何在rowediting事件中启用嵌套在gridview内的文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在RowEditing事件中启用嵌套在Gridview内的文本框?



How can i enable textbox nested inside Gridview in RowEditing event ?

protected void MyGrid_RowEditing(object sender, GridViewEditEventArgs e)
        {
            string CampID;
            //int id = Convert.ToInt32(MyGrid.DataKeys[e.].ToString());
            CampID = (Session["CampaignID"].ToString());
            mf.UpdateStatus(CampID, 'X');
            MyGrid.EditIndex = e.NewEditIndex;
            //string lblOfferType = MyGrid.Rows[e.NewEditIndex].Cells[4].Text;
            GridViewRow currentRow = this.MyGrid.Rows[e.NewEditIndex];

            string lblOfferType = (currentRow.FindControl("lblOffer_Type") as Label).Text;
            //string freeQty = (currentRow.FindControl("txtFree_Qty") as TextBox).Text;
            //string discPercent = (currentRow.FindControl("txtDisc_Percent") as TextBox).Text;
            //TextBox discValue = (currentRow.FindControl("txtDisc_Value") as TextBox);
            //string offerPrice = (currentRow.FindControl("txtOffer_Price") as TextBox).Text;
            //string freeArticle = (currentRow.FindControl("txtFree_Article") as TextBox).Text;

            if (lblOfferType == "VALUE DISCOUNT")
            {
                GridViewRow row = (GridViewRow)((Control)sender).NamingContainer;
                GridViewRow currentRow1 = this.MyGrid.Rows[e.NewEditIndex];
                ((TextBox)MyGrid.Rows[e.NewEditIndex].FindControl("txtDisc_Value")).Enabled = false;
                //discValue.Enabled = true;
                //(currentRow.FindControl("txtDisc_Value") as TextBox).Enabled = true;
                //((TextBox)currentRow.FindControl("txtDisc_Value")).Enabled = true;
            }
}







错误:对象引用未设置为实例。



请提供解决方案。



我尝试过:






Error: Object reference not set to an instance.

Please provide the solution.

What I have tried:

protected void MyGrid_RowEditing(object sender, GridViewEditEventArgs e)
        {
            string CampID;
            //int id = Convert.ToInt32(MyGrid.DataKeys[e.].ToString());
            CampID = (Session["CampaignID"].ToString());
            mf.UpdateStatus(CampID, 'X');
            MyGrid.EditIndex = e.NewEditIndex;
            //string lblOfferType = MyGrid.Rows[e.NewEditIndex].Cells[4].Text;
            GridViewRow currentRow = this.MyGrid.Rows[e.NewEditIndex];

            string lblOfferType = (currentRow.FindControl("lblOffer_Type") as Label).Text;
            //string freeQty = (currentRow.FindControl("txtFree_Qty") as TextBox).Text;
            //string discPercent = (currentRow.FindControl("txtDisc_Percent") as TextBox).Text;
            //TextBox discValue = (currentRow.FindControl("txtDisc_Value") as TextBox);
            //string offerPrice = (currentRow.FindControl("txtOffer_Price") as TextBox).Text;
            //string freeArticle = (currentRow.FindControl("txtFree_Article") as TextBox).Text;

            if (lblOfferType == "VALUE DISCOUNT")
            {
                GridViewRow row = (GridViewRow)((Control)sender).NamingContainer;
                GridViewRow currentRow1 = this.MyGrid.Rows[e.NewEditIndex];
                ((TextBox)MyGrid.Rows[e.NewEditIndex].FindControl("txtDisc_Value")).Enabled = false;
                //discValue.Enabled = true;
                //(currentRow.FindControl("txtDisc_Value") as TextBox).Enabled = true;
                //((TextBox)currentRow.FindControl("txtDisc_Value")).Enabled = true;
            }
}

推荐答案

试试这个

TextBox txtDisc_Value =(TextBox)MyGrid.Rows [e.NewEditIndex ]。.FindControl(txtDisc_Value);

txtDisc_Value.Enabled = false;
try this
TextBox txtDisc_Value =(TextBox)MyGrid.Rows[e.NewEditIndex].FindControl("txtDisc_Value");
txtDisc_Value.Enabled = false;


谢谢,但是在执行你的代码行后会出现这个错误: -



对象引用未设置为对象的实例。
Thanks, but this error is showing after executing your line of code:-

"Object reference not set to an instance of an object."


请提供更好的解决方案。

先谢谢。
Please provide better solution to the problem.
Thanks in Advance.


这篇关于如何在rowediting事件中启用嵌套在gridview内的文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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