惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
Attack and Defense Labs
Attack and Defense Labs
V2EX - 技术
V2EX - 技术
O
OpenAI News
S
Secure Thoughts
H
Heimdal Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Schneier on Security
Schneier on Security
H
Hacker News: Front Page
S
Security Affairs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
The Register - Security
The Register - Security
GbyAI
GbyAI
Cloudbric
Cloudbric
MongoDB | Blog
MongoDB | Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
Forbes - Security
Forbes - Security
Y
Y Combinator Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Scott Helme
Scott Helme
Hacker News - Newest:
Hacker News - Newest: "LLM"
The Cloudflare Blog
Recorded Future
Recorded Future
人人都是产品经理
人人都是产品经理
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
Webroot Blog
Webroot Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog
T
Tor Project blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
Hacker News: Ask HN
Hacker News: Ask HN
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
I
Intezer
V
V2EX
T
Tailwind CSS Blog
SecWiki News
SecWiki News
NISL@THU
NISL@THU
C
Check Point Blog

博客园 - ★金★

导出EXCEL table变宽格式 IE11兼容性设定 C#获取多个相同name值 DIV左右行 Jquery绑定Select下拉菜单 SQL中多项合并时请加ISNULL WebForm设置URL路由后要照顾好之前的连接 Repeater中获取HTML select 值 NPOI生成Excel 博文阅读密码验证 - 博客园 Firefox中不支持parentElement用parentNode取代 jquery给span赋值的时候出现firefox不兼容 jquery表单验证增加确认及可选不需要验证的方法 javascript可用数组取代case格式化字符 display和visibility的区别 SQL中Replace替换引号 javascript动态添加删除行后行内计算及取值 取代RadioButtonList及RadioButton方法
Repeater中绑定下拉菜单的2种方法
★金★ · 2011-07-04 · via 博客园 - ★金★

1.第一种方法,Repeater中绑定DropDownList实现。

<asp:DropDownList ID="ddlfixs" runat="server" appenddatabounditems="true">
      <asp:ListItem Value="">请选择治具</asp:ListItem></asp:DropDownList>
      <asp:HiddenField ID="hdfixid" runat="server" Value='<%# Eval("Fixid")%>' />
        protected void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            DropDownList ddlfixs = e.Item.FindControl("ddlfixs") as DropDownList;
            //HtmlSelect ddltools = e.Item.FindControl("ddltools") as HtmlSelect;

            WebClass.Toolfix tmpp = new WebClass.Toolfix();
            ddlfixs.DataSource = tmpp.ListFixShow();
            ddlfixs.DataTextField = "Names";
            ddlfixs.DataValueField = "Id";
            ddlfixs.DataBind();

            ddlfixs.SelectedValue = ((HiddenField)e.Item.FindControl("hdfixid")).Value;
        }
取值:
            string strfixs = "";
            foreach (RepeaterItem rptItem in myRepeater.Items)
            {
                DropDownList ddl = rptItem.FindControl("ddlfixs") as DropDownList;
                strfixs += ddl.SelectedValue + ",";
            }
            strfixs = strfixs.Remove(strfixs.Length - 1);

这种方法很不好,会生成;<select name="myRepeater$ctl02$ddlfixs" id="myRepeater_ddlfixs_2">类似的代码,如果javascript控制添加多行操作,很难控制。

2.第二方法,从后台生成HTML代码。

<%# BinGxData(Eval("Gxid").ToString())%>
        public string BinGxData(string strgxid)
        {
            WebClass.TooList tmp = new WebClass.TooList();
            DataTable dt=tmp.ListToolTable();
            string strMsg = "<select name='ddltools' id='ddltools'>";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string str1 = (strgxid == dt.Rows[i]["id"].ToString() ? "selected='selected'" : "");
                strMsg = strMsg + "<option value='" + dt.Rows[i]["id"].ToString() + "' " + str1 + ">" + dt.Rows[i]["names"].ToString() + "</option>";
            }
            strMsg = strMsg + "</select>";
            return strMsg; 
        }

取值好简单:Request.Form["ddltools"];即可。
此方法干净利索,尤其在添加多行操作中很好控制。