This is a migrated thread and some comments may be shown as answers.

[Solved] Using RADGRid with Custom Controls and Namespaces (CS0103)

4 Answers 176 Views
Grid
This is a migrated thread and some comments may be shown as answers.
B
Top achievements
Rank 1
B asked on 09 May 2008, 10:17 PM

I am creating a custom control to display an image based on a database field. If field=1, show image1, if field=2, show image2, etc.

The following error appears..."CS0103: The name 'SetPercentageCompleteImage' does not exist in the current context". It seems to me that the default.aspx page cannot see the SetPercentageComplete function in PercentComplete.ascx.cs so I think it is namespace problem. I have tried to configure a namespace but this just generated more errors.

The key elements of the user control and default page are listed below:

PercentComplete.ascx 

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="PercentageCompleteImage.ascx.cs" Inherits="PercentageCompleteImage" %>

<asp:Image ID="Image1" runat="server" ImageUrl="~/0_Perc_Comp.png" OnLoad="SetPercentageCompleteImage" />

 

PercentComplete.ascx.cs  

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

public partial class PercentageCompleteImage : System.Web.UI.UserControl

{

protected void Page_Load(object sender, EventArgs e)            {        }

public String PerCentValue

           { getset ;  }public void SetPercentageCompleteImage(object sender, EventArgs e)

{

int x = Convert.ToInt32(PerCentValue);

switch (x) {

case 0: Image1.ImageUrl = "~/0_Perc_Comp.png"; return;

case 1: Image1.ImageUrl = "~/10_Perc_Comp.png"; return;

case 2: Image1.ImageUrl = "~/20_Perc_Comp.png"; return;

case 3: Image1.ImageUrl = "~/30_Perc_Comp.png"; return;

}  }  }

 

Elements of Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register src="PercentageCompleteImage.ascx" tagprefix="uc1" tagname="PercentageCompleteImage" %>

<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>   .....using this for the RADGrid with control in a template

....

 

The template where the problem occurs. 

<telerik:GridTemplateColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType" ForceExtractValue="None" UniqueName="column" HeaderText="Status">

    <EditItemTemplate>      <asp:TextBox runat="server"></asp:TextBox>    </EditItemTemplate>

    <ItemTemplate> <uc1:PercentageCompleteImage  ID="PercentageCompleteImage1" runat="server" PerCentValue='<%# SetPercentageCompleteImage(Eval("Status")) %>' />  </ItemTemplate>   .....this is the problem line (referencing the Status field which is a GridBoundColumn further up the page).

</telerik:GridTemplateColumn>

Thanks in advance

Brad

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 10 May 2008, 10:53 AM
Hi Brad,

You need to declare reference to the user control where this method is declared.

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
B
Top achievements
Rank 1
answered on 10 May 2008, 12:28 PM
Vlad,
Hi. Thanks for the response. Could you give me a bit more detail to point me in the right direction.
Thanks
Brad
0
Accepted
Vlad
Telerik team
answered on 10 May 2008, 02:11 PM
Hi Brad,

Since PerCentValue is a property of the same user control you can call your method in the property setter instead of getting reference to the control and control type to access the control methods.

All the best,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
B
Top achievements
Rank 1
answered on 18 May 2008, 12:06 PM
Vlad,
Hi. Thanks for the advice.
I worked out that the method in the user control had to changed from OnLoad to OnDataBinding.
Works fine now.
Thanks
Brad
Tags
Grid
Asked by
B
Top achievements
Rank 1
Answers by
Vlad
Telerik team
B
Top achievements
Rank 1
Share this question
or