无法从列表视图中的selectedindexchanged中找到

无法从列表视图中的selectedindexchanged中找到

本文介绍了无法从列表视图中的selectedindexchanged中找到控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望能够从listview中的SelectIndexChanged中找到控件..

want be able to find control from SelectIndexChanged in listview..

TexBox comment= (TextBox)item.FindControl("TextBoxL");// this code in not working in SelectIndexChanged




TextBox btnModify = (TextBox)FindControl("TextBoxL");// i tried this one also but this is also not working...




protected void ListView1_SelectedIndexChanged(object sender, EventArgs e)
{
   TextBox btnModify = (TextBox)FindControl("TextBoxL");

   SqlConnection c = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);

   int myindex = ListView1.SelectedIndex;
   string myId = ListView1.DataKeys[myindex][0].ToString();
   //testing the value returned correctly
   Response.Write(myId);
   SqlCommand cmd = new SqlCommand("insert into rply(task_id,comment,rply_name,rpl_date)values('" +  myId + "','" + btnModify.Text + "','" + s2 + "','" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "')", c);

   c.Open();
   cmd.ExecuteNonQuery();
   c.Close();
}

推荐答案


public void GetControl(Control control)
    {
        //parent could be listview ..so use its id
        foreach (Control ctrl in parent.Controls)
        {

            if (ctrl.GetType() == typeof(TextBox))
            {
              //control  found  ... return here
            }
           else
           {
              GetControl(ctrl);
           }

        }
    }



这篇关于无法从列表视图中的selectedindexchanged中找到控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 14:40