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