[問題] asp.net itemtemplate中dropdownlist取值

看板Web_Design作者 (承諾不過是謊言)時間11年前 (2014/10/28 18:00), 11年前編輯推噓6(603)
留言9則, 5人參與, 最新討論串1/1
如題 今天如果我想要用類似dropdownlist.SelectedValue的方法取值 有辦法嗎? 因為我今天下拉選單寫在edititemtemplate 裡面 類似以下的寫法 <asp:TemplateField HeaderText="類別"> <EditItemTemplate> <asp:DropDownList ID="ddltype" runat="server"> <asp:ListItem>A</asp:ListItem> <asp:ListItem>B</asp:ListItem> <asp:ListItem>C</asp:ListItem> <asp:ListItem>D</asp:ListItem> asp:DropDownList> <asp:Label ID="type" runat="server" Text='<%#Bind("type") %>' Visible="False">asp:Label> EditItemTemplate> <ItemStyle Wrap="False" /> <asp:Label ID="label1" runat="server" Text='<%#Bind("type") %>'>asp:Label> ItemTemplate> asp:TemplateField> 我在背景裡面用了這句 ddltype.SelectedValue 卻沒有辦法取得值 錯誤跳出ddltype尚未宣告 想請問各位有什麼辦法 可以單純只要讓我在編輯時可以取得dropdownlist裡面的值 謝謝!! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.243.64.27 ※ 文章網址: http://www.ptt.cc/bbs/Web_Design/M.1414490406.A.A45.html ※ 編輯: moon128 (111.243.64.27), 10/28/2014 18:00:30

10/28 18:41, , 1F
用FindCtrol?
10/28 18:41, 1F

10/28 18:49, , 2F
您好可以給完整一點的code 嗎
10/28 18:49, 2F
您好 我的那一column設定就只有這樣 在編輯鈕按下的時候會出現下拉式選單供我選擇 請問有辦法像一般的dropdownlist直接取得值嗎? 還是有關聯哪一部分我再貼上 全部篇幅有點大 ※ 編輯: moon128 (111.243.64.27), 10/28/2014 19:05:34 ※ 編輯: moon128 (111.243.64.27), 10/28/2014 19:08:23

10/28 19:09, , 3F
這位溫拿,您可以寫一個簡單的sample呀
10/28 19:09, 3F

10/28 19:10, , 4F
或者把sample code寄給魯蛇我幫您看看吧
10/28 19:10, 4F

10/29 01:02, , 5F
要用FindCtrol去找
10/29 01:02, 5F

10/29 01:03, , 6F
1.把index存在commandargument,依照index去findctrl
10/29 01:03, 6F

10/29 01:03, , 7F
2.抓出button的namingcontainer,用這個去findctrl
10/29 01:03, 7F

10/29 01:04, , 8F
findcontrol("ddltype")
10/29 01:04, 8F

10/29 20:04, , 9F
謝謝各位的回答 用findcontrol找到了 感恩!!
10/29 20:04, 9F
文章代碼(AID): #1KJsacf5 (Web_Design)