C# .NET - Error : lblprojectname doesnot exist in the current context

Asked By sindhu krothapalli on 16-Mar-13 03:38 AM
Hi


            In my application i want's to bind the data to datalist control.

Here is the code which i have written in my class file.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//using Sql.Data.SqlClient;
using System.Data.SqlClient;
using System.Globalization;
using System.IO;
using MySql.Data.MySqlClient;


public class jsrgroup
{
    MySqlConnection myCon;
    MySqlCommand myCommand = new MySqlCommand();
    MySqlDataAdapter myAdapter;


    DataSet myDataSet = new DataSet();
    private string transactiontypeid;
    public string getConnection()
    {
        return (ConfigurationManager.ConnectionStrings["connection"].ToString());


    }
    public DataSet fnSelectprojectdetails(int transactiontypeid)
    {
        myCon = new MySqlConnection(getConnection());
        myAdapter = new MySqlDataAdapter("select transactiontypeid.projectname,transactiontypeid.image,transactiontypeid.locality,transactiontypeid.price,transactiontypeid.plans,transactiontypeid.completiondate from transmaster where transactiontypeid=" + transactiontypeid + " ", myCon);
        myDataSet = new DataSet();
        myAdapter.Fill(myDataSet, "project");
        return myDataSet;
    }
}

----------------------------------------------------------------------------------------------------------------
Here is the source code of datalist control.

 <asp:DataList ID="dListItems" runat="server" CssClass= "project_gall" 
        Width="100%" BackColor="#ECF0F4" 
        RepeatColumns="3" CellPadding="6" CellSpacing="6" RepeatDirection="Horizontal" OnItemCommand="DataList2_ItemCommand">
                               <ItemTemplate>
                        <asp:Label ID="lblprojectname" runat="server"  Font-Bold="true" Font-Size="12px" CssClass="project_left h2" Text='<%# Eval ("projectname") %>'></asp:Label>
                     <div align="center" style="position: relative;">
 <asp:ImageButton ID="projectimage" runat="server" align="center" position="relative" width="150" border="0" CommandName="Details" CommandArgument='<%# Eval ("image") %>' />
                        </div>
                  <table width="200" border="0" cellpadding="0" cellspacing="0">
         <tr>
           <td height="10" colspan="2" class="des"></td>
           </tr>
         <tr>
           <td width="107" height="25" class="des">Location : </td>
           <td width="93" class="des1"><asp:Label ID="ldllocation" runat="server" Text='<%# Eval("locality") %>'></asp:Label>
           </td></tr> <tr>
           <td height="25" class="des">Price :</td>
           <td class="des1"><asp:Label ID="lblprice" runat="server" Text='<%# Eval("saleprice") %>'></asp:Label>
           </td></tr> <tr>
            <td height="25" class="des">Plans :</td>
           <td class="des1"><asp:Label ID="lblplans" runat="server" Text='<%# Eval("plans") %>'></asp:Label>
           </td></tr> <tr>
            <td height="25" class="des">Completion Date :</td>
           <td class="des1"><asp:Label ID="lbldate" runat="server" Text='<%# Eval("completiondate") %>'></asp:Label>
           </td></tr> 
            <tr>
           <td height="28" colspan="2" class="des"></td>
           </tr>
                      <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>
                      <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
         <tr><td height="25" class="des">
         <asp:ImageButton ID="imgenquirydetails" runat="server" width="93" height="23" border="0" ImageUrl="~/images/enquiery.jpg" alt="Flats in Raj Nagar Extension" />
         </td>
           <td class="des1">
            <asp:ImageButton ID="imgdetails" runat="server"  width="52" height="23" border="0" ImageUrl="~/images/detail.jpg" alt="Buy Apartment in Raj Nagar Extension"/>
</td>
         </tr>
       </table>
      </div>
                            
                          
                        </ItemTemplate>
                        <SeparatorStyle BorderColor="#FFC0C0" />
                    </asp:DataList>
-----------------------------------------------------------------------------------------------

Here is the code which i have written .aspx.cs page.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Configuration;
using MySql.Data.MySqlClient;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Text;




public partial class home : System.Web.UI.Page
{
   
    jsrgroup jfile = new jsrgroup();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["transactiontypeid"] != null)
            {


                DataSet ds = new DataSet();
                int transactiontypeid = 0;
                ds = jfile.fnSelectprojectdetails(int.Parse(Request.QueryString["transactiontypeid"].ToString()));
                if (ds.Tables[0].Rows.Count != 0)
                {
                    lblprojectname.Text = ds.Tables[0].Rows[0][1].ToString();
                    projectimage.ImageUrl = ds.Tables[0].Rows[0][2].ToString();
                    lbllocation.Text = ds.Tables[0].Rows[0][3].ToString();
                    lblprice.Text = ds.Tables[0].Rows[0][4].ToString();
                    lblplans.Text = ds.Tables[0].Rows[0][9].ToString();
                    lblcompletiondate.Text = ds.Tables[0].Rows[0][7].ToString();

                }


                ds.Dispose();
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }

    }


    protected void dListItems(object source, DataListCommandEventArgs e)
    {


        if (e.CommandName == "Details")
        {




            Response.Redirect("home.aspx");




        }
    }
}



 
Danasegarane Arunachalam replied to sindhu krothapalli on 16-Mar-13 08:24 PM
lblProjectname is inside the datalist control. This control will be created only when some data is populated into the datalist. And you cannot directly access this other standalone server control. What you want to do?