国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

TO feixr,DataGrid中的Radiobutton

2024-07-21 02:22:01
字體:
供稿:網(wǎng)友

商業(yè)源碼熱門下載www.html.org.cn

碰到的問題是如果用的是server端的radio控件的話
系統(tǒng)會自動的給它分配name以相互區(qū)分
這樣就破壞了我們單選的目的
但如果用一般的htmlcontrol,又不能保存狀態(tài)
所以我自己寫了一個用戶控件
給你參考一下,代碼如下:
userradio.ascx.cs

namespace examwebui
{
    using system;
    using system.data;
    using system.drawing;
    using system.web;
    using system.web.ui;
    using system.web.ui.webcontrols;
    using system.web.ui.htmlcontrols;
    using system.collections.specialized;  

    /// <summary>
    ///        webusercontrol1 的摘要說明。
    /// </summary>
    public abstract class userradio : system.web.ui.usercontrol
    {
        private string rvalue;
        private string rname;
        private string fvalue;
        private bool postcheck;

        private void page_load(object sender, system.eventargs e)
        {
            fvalue=this.page.request.form[this.name];
            if(this.rvalue==this.fvalue)
                postcheck=true;
        }

        protected override void render(htmltextwriter output)
        {
            string outstr;
            if(postcheck)
                outstr="<h3>value: <input name=" + this.name + " type=radio value=" + this.value + " checked> </h3>";
            else
                outstr="<h3>value: <input name=" + this.name + " type=radio value=" + this.value + " > </h3>";
            output.write(outstr);
        }

        public string value
        {
            get
            {
                return this.rvalue;
            }
            set
            {
                this.rvalue = value;                
            }
        }

        public string name
        {
            get
            {
                return this.rname;
            }
            set
            {
                this.rname = value;
            }
        }


        #region web form designer generated code
        override protected void oninit(eventargs e)
        {
            //
            // codegen:該調(diào)用是 asp.net web 窗體設(shè)計器所必需的。
            //
            initializecomponent();
            base.oninit(e);
        }
        
        ///        設(shè)計器支持所需的方法 - 不要使用
        ///        代碼編輯器修改此方法的內(nèi)容。
        /// </summary>
        private void initializecomponent()
        {
            this.load += new system.eventhandler(this.page_load);
        }
        #endregion
    }
}
userradio.ascx

<%@ control language="c#" autoeventwireup="false" codebehind="userradio.ascx.cs" inherits="examwebui.userradio" targetschema="http://schemas.microsoft.com/intellisense/ie5"%>

使用該控件的例子

test1.aspx

<%@ page language="c#" codebehind="test1.aspx.cs" autoeventwireup="false" inherits="examwebui.test1" %>
<%@ register tagprefix="dxuc" tagname="radio" src="userradio.ascx" %>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en" >
<html>
    <head>
        <title>test1</title>
        <meta name="generator" content="microsoft visual studio 7.0">
        <meta name="code_language" content="c#">
        <meta name="vs_defaultclientscript" content="javascript">
        <meta name="vs_targetschema" content="http://schemas.microsoft.com/intellisense/ie5">
    </head>
    <body ms_positioning="gridlayout">
        <form id="test1" method="post" runat="server">
            <font face="宋體">
                <asp:datagrid id="datagrid1" style="z-index: 101; left: 230px; position: absolute; top: 136px" runat="server" width="221px" height="189px">
                    <columns>
                        <asp:templatecolumn>
                        <itemtemplate>
                    <dxuc:radio id="rd1" runat=server value=<%#container.dataitem%> name="hahah"></dxuc:radio>
                        </itemtemplate>     
                        </asp:templatecolumn>
                    </columns>
                </asp:datagrid>                    
                <asp:button id=s1 runat=server></asp:button>   
                </font>
        </form>
    </body>
</html>

test1.aspx.cs

using system;
using system.collections;
using system.componentmodel;
using system.data;
using system.drawing;
using system.web;
using system.web.sessionstate;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.htmlcontrols;

namespace examwebui
{
    /// <summary>
    /// test1 的摘要說明。
    /// </summary>
    public class test1 : system.web.ui.page
    {
        protected system.web.ui.webcontrols.datagrid datagrid1;
    
        private void page_load(object sender, system.eventargs e)
        {
            system.collections.arraylist a=new system.collections.arraylist();
            a.add("a");
            a.add("b");
            a.add("c");

            this.datagrid1.datasource=a;
            this.datagrid1.databind();
        }

        #region web form designer generated code
        override protected void oninit(eventargs e)
        {
            //
            // codegen:該調(diào)用是 asp.net web 窗體設(shè)計器所必需的。
            //
            initializecomponent();
            base.oninit(e);
        }
        
        /// <summary>
        /// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改
        /// 此方法的內(nèi)容。
        /// </summary>
        private void initializecomponent()
        {    
            this.load += new system.eventhandler(this.page_load);

        }
        #endregion
    }
}

這種方法最大問題是必須每次bind,暫時還沒想著好的解決辦法:(
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 铜山县| 柯坪县| 汤阴县| 临洮县| 舟曲县| 屯昌县| 白玉县| 盘锦市| 蒙自县| 读书| 五家渠市| 茌平县| 周宁县| 沛县| 大荔县| 永平县| 临武县| 长岛县| 勃利县| 揭阳市| 浮梁县| 泽库县| 钦州市| 千阳县| 卢氏县| 平南县| 文山县| 扬中市| 兴业县| 陆河县| 镇康县| 荣昌县| 大渡口区| 连平县| 涡阳县| 乌什县| 洞头县| 河南省| 曲水县| 巴南区| 西乡县|