Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.Unit'

I am getting an error, for example, I cannot implicitly convert the type 'string' to 'System.Web.UI.WebControls.Unit' in the following code. How to fix it.

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        RadTab tab = new RadTab();
        tab.Text = string.Format("New Page {0}", 1);
        RadTabStrip1.Tabs.Add(tab);

        RadPageView pageView = new RadPageView();
        pageView.Height = "100px";
        RadMultiPage1.PageViews.Add(pageView);

        BuildPageViewContents(pageView, RadTabStrip1.Tabs.Count);
        RadTabStrip1.SelectedIndex = 0;
        RadTabStrip1.DataBind();

    }
}

Here I get the error. pageView.Height = "100px";

How to fix it?

+5
source share
6 answers

The error message says it all. You need to convert the value to in a System.Web.UI.WebControls.Unitmore specific way. Luckliy type Unithas a constructor with this ability:

pageView.Height = new System.Web.UI.WebControls.Unit("100px");
+3
source

Because it Heightdoes not have a string of type, but of type UnitSystem.Web.UI.WebControls.Unit enter code here.

Unit:

  • Unit.Pixel(100); // 100 px
  • Unit.Percent(10); // 10 %
  • Unit.Point(100); // 100 pt
  • Unit.Parse("100px"); // 100 px

Unit , , .

+5

pageView.Height = "100px";

to

pageView.Height = new Unit(100);

Height Unit, , Unit. Unit, Unit new; , Unit.

0

"100px";

new System.Web.UI.WebControls.Unit("100px");
0

Unit.

pageView.Height = Unit.Pixel(100);
0

This MSDN document is on how to use Units. In your case:

pageView.Height = new Unit("100px");
0
source

All Articles