国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 天水市| 隆德县| 固原市| 淅川县| 嘉兴市| 临沂市| 乌鲁木齐市| 巴彦淖尔市| 体育| 温泉县| 连山| 澄江县| 禹州市| 什邡市| 喀什市| 平阴县| 余庆县| 安多县| 浙江省| 神池县| 白沙| 清丰县| 杂多县| 和龙市| 乌兰察布市| 安远县| 西平县| 蒲江县| 兴和县| 门头沟区| 西畴县| 肥东县| 平舆县| 白山市| 安龙县| 双江| 金秀| 北票市| 大同县| 恭城| 泉州市|