English 中文(简体)
你们如何将内部的“(div)”置于正文法典中?
原标题:how do you set the innerhtml on a generic control (div) in c# code behind?
  • 时间:2011-03-10 19:53:29
  •  标签:
  • c#
  • webforms

我正试图将控制(div)积极添加到一个网页上:

 HtmlControl divControl = new html HtmlGenericControl("div");
 divControl.Attributes.Add("id", lb.Items[i].Value);
 divControl.Attributes.Add("innerHtml", "bob");
 divControl.Visible = true;
 this.Controls.Add(divControl);

但是,我如何确定控制本身的案文(innerhtml),因为控制本身似乎与内心一样。 Html作为属性存在,没有价值或案文选择?

Thanks

最佳回答

如果你将“divControl”改为HtmlGenericControl,那么你就应当能够确定国内财产:

HtmlGenericControl divControl = new HtmlGenericControl("div"); 
问题回答

页: 1 在HtmlControl范围内:

HtmlControl divControl = new html HtmlGenericControl("div");
divControl.Attributes.Add("id", lb.Items[i].Value);
divControl.Visible = true; // Not really necessary
this.Controls.Add(divControl);

divControl.Controls.Add(new LiteralControl("<span>Put whatever <em>HTML</em> code here.</span>"));
    HtmlGenericControl divControl = new  HtmlGenericControl("div");
    divControl.Attributes.Add("id", "myDiv");
    divControl.InnerText = "foo";
    this.Controls.Add(divControl);

If you re just adding text, this should do it:

Literal l = new Literal();
l.Text = "bob";

HtmlControl divControl = new HtmlGenericControl("div");
divControl.Attributes.Add("id", "someId");
divControl.Visible = true;
divControl.Controls.Add(l);

this.Controls.Add(divControl);

Edit: you can embed HTML in a literal as well.

我更喜欢采用这种方式(通过使用许可证):

Controls.Add(new Literal { Text = string.Format(@"<div id= {0} ><span>some text</span></div>", lb.Items[i].Value) });




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签