作者moon128 (承諾不過是謊言)
看板Web_Design
標題[問題] asp.net itemtemplate中dropdownlist取值
時間Tue Oct 28 18:00:04 2014
如題
今天如果我想要用類似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
推 GoalBased: 用FindCtrol? 10/28 18:41
推 BigLoser: 您好可以給完整一點的code 嗎 10/28 18:49
您好 我的那一column設定就只有這樣
在編輯鈕按下的時候會出現下拉式選單供我選擇
請問有辦法像一般的dropdownlist直接取得值嗎?
還是有關聯哪一部分我再貼上 全部篇幅有點大
※ 編輯: moon128 (111.243.64.27), 10/28/2014 19:05:34
※ 編輯: moon128 (111.243.64.27), 10/28/2014 19:08:23
推 BigLoser: 這位溫拿,您可以寫一個簡單的sample呀 10/28 19:09
→ BigLoser: 或者把sample code寄給魯蛇我幫您看看吧 10/28 19:10
推 pm2001: 要用FindCtrol去找 10/29 01:02
推 CrazyAngel: 1.把index存在commandargument,依照index去findctrl 10/29 01:03
→ CrazyAngel: 2.抓出button的namingcontainer,用這個去findctrl 10/29 01:03
推 pm2001: findcontrol("ddltype") 10/29 01:04
→ moon128: 謝謝各位的回答 用findcontrol找到了 感恩!! 10/29 20:04