访问函数内部数据列表中的控件 [英] Accessing Control inside datalist inside a function

查看:62
本文介绍了访问函数内部数据列表中的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我想访问一个函数内数据列表内的控件.但这给了我一个错误,那就是对象引用未设置为对象的实例.

这是该函数的代码

Hi all!!

i want to access a control which is inside the datalist inside a function. but it''s giving me error that object reference not set to an instance of object.

here is the code for the function

private void databind()
   {
      pnl1.Visible = true;
      con.Open();

       SqlDataAdapter da = new SqlDataAdapter("select CompanyName,JobID,JobTitle,Industry,Requirement,CompanyProfile,Salary,Location,Emailid,PhoneNo,MobileNo,Address,ContactPerson  from Jobs where Industry = ''" + DropDownList1.SelectedItem.Text.ToString() + "''", con);
       DataSet ds = new DataSet();
       da.Fill(ds);
       da.Fill(dt);
       DataList1.DataSource = ds;
       DataList1.DataBind();

       SqlCommand cmd2 = new SqlCommand("Select UserId,JobID from Applied", con);
       SqlDataReader dr1;
       dr1 = cmd2.ExecuteReader();

       while (dr1.Read())
       {
           if (Session["JobSeeker"].ToString() == (dr1.GetValue(0).ToString()) && (dt.Rows[0][1].ToString() == dr1.GetValue(1).ToString()))
           {
              Image img = (Image)DataList1.FindControl("imgApplied");
               img.Visible = true;
               //img1.Visible = false;
           }

       }

   }

推荐答案

我解决了它. :)

我用过

i solved it. :)

i used

((Image)DataList1.Items[0].FindControl("imgApplied")).Visible = true;




:)




:)


这篇关于访问函数内部数据列表中的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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