C_Sharp 板


LINE

碰到的问题挺难确定要去DB还是网设版问XD 不过用的是C#就先来问问看罗 这是一个ASP.NET网页的其中一段 void Page_Load(object sender, EventArgs e) { string dbString = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + Server.MapPath("db8_1.mdb"); OleDbConnection dbConn = new OleDbConnection(dbString); dbConn.Open(); string cmdString = "SELECT * FROM data"; OleDbCommand dbCommand = new OleDbCommand(cmdString, dbConn); OleDbDataReader myReader = dbCommand.ExecuteReader(); string[ , ] Myarr = new string[20, 7] ; int i = 0; while (myReader.Read( )) { Myarr[i, 0] = (string)myReader["Question"]; Myarr[i, 1] = (string)myReader["A"]; Myarr[i, 2] = (string)myReader["B"]; Myarr[i, 3] = (string)myReader["C"]; Myarr[i, 4] = (string)myReader["D"]; Myarr[i, 5] = (string)myReader["E"]; Myarr[i, 6] = (string)myReader["Answer"]; i++; } //到此程式执行上都没有发生问题 //有使用非以下的方法测试了前几个阵列和 Label还有RadioButtonList之间的系结,也是ok的 //但是换成了以下的方法却又发生了错误 Label L = new Label( ); RadioButtonList RBL = new RadioButtonList( ); for (int n = 1; n <= 10; n++) { L = (Label)FindControl("L" + n); RBL = (RadioButtonList)FindControl("RBL" + n); L.Text = (string)Myarr[n-1, 0]; //执行时发生错误的地方。 "并未将物件参考设定为物件的执行个体" //在学期中是采用L.Text = (string)myReader.Read["Question"]; 并没有此问题的产生 //不过这次需求不太一样,换从阵列读取值,但是问题似乎又不在阵列上 难道是L在宣告上有什麽错误发生吗? RBL.Items[0].Text = (string)Myarr[n-1, 1]; RBL.Items[1].Text = (string)Myarr[n-1, 2]; RBL.Items[2].Text = (string)Myarr[n-1, 3]; RBL.Items[3].Text = (string)Myarr[n-1, 4]; RBL.Items[4].Text = (string)Myarr[n-1, 5]; RBL.Items[0].Value = "A"; RBL.Items[1].Value = "B"; RBL.Items[2].Value = "C"; RBL.Items[3].Value = "D"; RBL.Items[4].Value = "E"; } <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="L1" runat="server"></asp:Label> <asp:RadioButtonList ID="RBL1" runat="server"> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> </asp:RadioButtonList> <asp:Label ID="L2" runat="server"></asp:Label> <asp:RadioButtonList ID="RBL2" runat="server"> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> </asp:RadioButtonList> <asp:Label ID="L3" runat="server"></asp:Label> <asp:RadioButtonList ID="RBL3" runat="server"> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> </asp:RadioButtonList> <asp:Label ID="Ll4" runat="server"></asp:Label> <asp:RadioButtonList ID="RBL4" runat="server"> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> </asp:RadioButtonList> <asp:Label ID="L5" runat="server"></asp:Label> <asp:RadioButtonList ID="RBL5" runat="server"> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> </asp:RadioButtonList> <asp:Label ID="L6" runat="server"></asp:Label> <asp:RadioButtonList ID="RBL6" runat="server"> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> </asp:RadioButtonList> <asp:Label ID="L7" runat="server"></asp:Label> <asp:RadioButtonList ID="RBL7" runat="server"> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> </asp:RadioButtonList> <asp:Label ID="L8" runat="server"></asp:Label> <asp:RadioButtonList ID="RBL8" runat="server"> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> </asp:RadioButtonList> <asp:Label ID="L9" runat="server"></asp:Label> <asp:RadioButtonList ID="RBL9" runat="server"> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> </asp:RadioButtonList> <asp:Label ID="L10" runat="server"></asp:Label> <asp:RadioButtonList ID="RBL10" runat="server"> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> <asp:ListItem></asp:ListItem> </asp:RadioButtonList> </div> </form> </body> </html> --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.143.23.190 忘了补发生什麽事 ※ 编辑: denby 来自: 220.143.23.190 (02/10 12:28)
1F:→ optimist9266:用即时运算去找,错误那行一定有一个是null去找为什 02/10 12:48
2F:→ optimist9266:是null, 02/10 12:48
3F:→ denby:怎麽用即时运算呢? 设计模式中没办法用 也没用过Orz 02/10 12:50
4F:→ denby:用逐步执行 找到L是null 但是,不是有宣告了吗? 02/10 12:55
5F:→ ssccg:L = (Label)FindControl("L" + n); 02/10 13:15
6F:→ ssccg:你Page里要已经有ID为L1 ~ L10的Label 02/10 13:16
7F:→ denby:确定是有的 02/10 13:17
附上page的部分 ※ 编辑: denby 来自: 220.143.23.190 (02/10 13:31)
8F:→ denby:@_@ L4变成L14 这个是问题的原因吗? 02/10 14:09
9F:→ juriolegend:用datelist+sqldatasource去系结radiobuttonlist 02/11 02:14
10F:→ juriolegend:应该比较容易吧 02/11 02:14
11F:→ denby:不过我的流程并不是那样耶 只能顺着自己的意思罗XD 02/11 19:49







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Tech_Job站内搜寻

TOP