Response.Write(div1.Style["BACKGROUND-COLOR"].ToString());<div id="div1" style="BACKGROUND-COLOR: silver" runat="server">dfsdfsdf </div>相关的看这个帮助CssStyleCollection

解决方案 »

  1.   

    在html里:
         <div id="div1" runat="server"></div>
    在.cs里:
         protected System.Web.UI.HtmlControls.HtmlGenericControl div1;
         Page_Load()等函数里:
         div1.Attributes["bgcolor"] = "Wheat";
         div1.InnerHtml= "kaokao";
      

  2.   

    必须在.cs里
    protected System.Web.UI.HtmlControls.HtmlGenericControl div1;
      

  3.   

    在cs里声明
    protected System.Web.UI.HtmlControls.HtmlGenericControl Div1;加属性:
    Div1.Style.Add("background-color","....");
    取:
    string s = Div1.Style["background-color"].ToString();
    注意,分大小写的!
      

  4.   

    我記得有個getSrcElement, javascript函數可以取得到.
    你去查查getsrcelement的用法
      

  5.   

    我用string s = Div1.Style["background-color"].ToString();取值时
    说是“未将对象设置到实例”。
    这是怎么回事啊?
      

  6.   

    IEnumerator keys = Ninediv.Style.Keys.GetEnumerator();
    while (keys.MoveNext()) 
    {
    String key = (String)keys.Current;
    string ss = key + "=" + Ninediv.Style[key] + "<br>";
    }
    试试看,就知道应该是用大写了。
        string ss = Ninediv.Style["BACKGROUND-COLOR"] + "<br>";
      

  7.   

    请问:我的DIV是动态生成的
    protected System.Web.UI.HtmlControls.HtmlGenericControl Div1;
    这句话是否在动态生成DIV的时候会自动写入cs文件呢?要是不行怎么做呢?
    还有,要是在DIV中加了runat属性成为服务器节点,我还要在客户端对其进行操作
    ,移动,即改变style里面的位置属性,会不会产生不断刷屏的现象?
      

  8.   

    DIV动态生成?
    这个我就不知道了。
    要是在DIV中加了runat属性成为服务器节点,我还要在客户端对其进行操作
    ,移动,即改变style里面的位置属性时,我倒是没有试过会不会刷屏,不过改变其颜色属性时倒不会刷屏。
      

  9.   

    是回传的吗?先用容器取到id号,动态生成时不能直接用div1.Properties取到的
    <form runat=server id="form1">
    <div id="abc" runat=server>
    ...
    </form>在取数据的时候用
    form1.FindControls["div"]
    这样得到的是一个object,再转换成DIV就可以了,我用过动态生成radiobutton然后用这个方法得到值,可能是一样的吧,你可以试一下。
      

  10.   

    这个动态生成控件是怎么生成的啊?
    贴个具体动态生成的例子可以吗?
    phoenixsbk(凤之泪痕)能把你  动态生成radiobutton并得到其属性值的代码贴出来让我学习一下吗?
    谢谢!
      

  11.   

    html控件加了runat=server不会自动刷新的,除非你为它编写了服务器端的事件。动态生成的DIV不会自动在服务器端声明的,所以必须用phoenixsbk(凤之泪痕)兄取控件ID的方法。
      

  12.   

    这个动态生成控件是怎么生成的啊?
    贴个具体动态生成的例子可以吗?
    phoenixsbk(凤之泪痕)能把你  动态生成radiobutton并得到其属性值的代码贴出来让我学习一下吗?
    谢谢!
      

  13.   

    不好意思,一直没看到这个帖子,我把代码贴给你:
    DataTable vote=db.ExecuteSingleQuery("select * from [vote] where vote_bbs="+bbsid,"votetable");
    foreach(DataRow myrow in vote.Rows)
    {
    total+=Int32.Parse(myrow["vote_number"].ToString());
    }
    if(total==0)
    {total=1;}
    int color=0;
    foreach(DataRow voterow in vote.Rows)
    {
    TableRow mainvoterow=new TableRow();

    TableCell mainvotetitlecell=new TableCell();
    RadioButton mainvotetitleradio=new RadioButton();
    mainvotetitleradio.Text=voterow["vote_text"].ToString();
    mainvotetitleradio.ID="radio"+voterow["ID"].ToString();
    mainvotetitleradio.GroupName="voteradio";
    mainvotetitlecell.Controls.Add(mainvotetitleradio);
    mainvotetitlecell.Font.Name="宋体";
    mainvotetitlecell.Width=Unit.Percentage(30);
    mainvotetitlecell.BorderWidth=2;
    mainvoterow.Cells.Add(mainvotetitlecell);

    if(voteid==1)
    {
    double wpercent;
    wpercent=double.Parse(voterow["vote_number"].ToString())/total*100;
    TableCell mainvoteshowcell=new TableCell();
    mainvoteshowcell.Text="<img src='images/"+color.ToString()+".gif' border='0' width='"+wpercent.ToString("#.00")+"%' height='8'>"+voterow["vote_number"].ToString()+"票";
    mainvoteshowcell.Font.Name="宋体";
    mainvoteshowcell.Width=Unit.Percentage(60);
    mainvoteshowcell.BorderWidth=2;
    mainvoterow.Cells.Add(mainvoteshowcell);

    TableCell mainvotecountcell=new TableCell();
    mainvotecountcell.Text=wpercent.ToString("#.00")+"%";
    mainvotecountcell.Font.Name="宋体";
    mainvotecountcell.Width=Unit.Percentage(10);
    mainvotecountcell.BorderWidth=2;
    mainvotecountcell.HorizontalAlign=HorizontalAlign.Center;
    mainvoterow.Cells.Add(mainvotecountcell);
    }
    else
    {
    TableCell mainvotenamecell=new TableCell();
    string votepeople;
    votepeople=voterow["vote_people"].ToString();
    if(votepeople!="")
    {
    mainvotenamecell.Text=votepeople.Substring(1);
    }
    else
    {
    mainvotenamecell.Text=votepeople;
    }
    mainvotenamecell.Font.Name="宋体";
    mainvotenamecell.Width=Unit.Percentage(70);
    mainvotenamecell.BorderWidth=2;
    mainvoterow.Cells.Add(mainvotenamecell);
    }
    mainvotetable.Rows.Add(mainvoterow);

    color++;
    if(color==5)
    {color=0;}
    }

    TableRow mainvotebuttonrow=new TableRow();
    TableCell mainvotebuttoncell=new TableCell();
    Button mainvotebutton=new Button();
    mainvotebutton.Text="投票";
    mainvotebutton.Click+=new EventHandler(this.Vote);
    mainvotebutton.ID="votebutton";
    mainvotebuttoncell.Controls.Add(mainvotebutton);
    mainvotebuttoncell.HorizontalAlign=HorizontalAlign.Center;
    mainvotebuttoncell.ColumnSpan=voteid+2;
    mainvotebuttonrow.Cells.Add(mainvotebuttoncell);
    mainvotetable.Rows.Add(mainvotebuttonrow);
    public void Vote(object o,EventArgs e)
    {
                       int voteid=0;
    db.Open();
    OleDbDataReader pickvoteid=db.ExecuteReader("select vote_bbs,ID from [vote] where vote_bbs="+Int32.Parse(Session["replyid"].ToString()));
    while(pickvoteid.Read())
    {
    RadioButton checkit=(RadioButton)(mainvotetable.FindControl("radio"+pickvoteid["ID"].ToString()));
    if(checkit.Checked)
    {
    voteid=Int32.Parse(pickvoteid["ID"].ToString());
    }
    }
    pickvoteid.Close();
    db.Close();
    }
    其中有些是我自己写的类,你主要看RADIOBUTTON就可以了,呵呵,不好意思