从列表框控件中的选定项填充标签 [英] populate a label from selected item in listbox control
本文介绍了从列表框控件中的选定项填充标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个从db填充的列表框。使用模态弹出窗口和面板时,单击选择用户按钮时将显示此列表框。当从此列表中选择特定用户并单击添加用户按钮时,我想填充具有特定用户名的标签。我似乎无法填充标签。其他一切都有效。任何想法???
这是我的asp代码:
I have created a listbox which is populated from a db. Using modal popup and panels, this listbox appears when the select user button is clicked. When a specific user is selected from this list and the add user button is clicked, I would like to populate a label with the specific user name. I cant seem to get the label populated. Everything else works. Any ideas???
this is my asp code:
<asp:Label ID="UserId" runat="server"></asp:Label>
<asp:Label ID="UserName" runat="server" Font-Bold="true" ForeColor="#97b23c" Font-Size="14px"></asp:Label>
<br />
<asp:Button ID="SelectUserBtn" runat="server" Text="Select User" />
</td>
<td>
<asp:Panel ID="Pnl" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<h4>List Of Available Users</h4>
<asp:ListBox ID="SourceList" runat="server" DataSourceID="SqlDataSource1"
DataTextField="FullName" DataValueField="UserId" Height="160" Width="200"
></asp:ListBox><br />
<asp:Button ID="OKBtn" runat="server" Text="Add User" OnClick="OkBtn_Click" />
<asp:Button ID="CancelBtn" runat="server" Text="Cancel" /><br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:sos_dmsConStr %>"
SelectCommand="SELECT [UserId], [FullName] FROM [UserProfiles]">
</asp:SqlDataSource>
</asp:Panel>
<asp:ModalPopupExtender ID="MPEUserList" runat="server" TargetControlID="SelectUserBtn" PopupControlID="Pnl" OkControlID="OKBtn" BackgroundCssClass="ModalBackground" DropShadow="true" CancelControlID="CancelBtn">
</asp:ModalPopupExtender>
我的代码背后:
my code behind:
protected void OkBtn_Click(object sender, EventArgs e)
{
UserId.Text = SourceList.SelectedItem.Value;
UserName.Text = SourceList.SelectedItem.Text;
}
推荐答案
ConnectionStrings:sos_dmsConStr %>
< span class =code-attribute> SelectCommand = SELECT [UserId],[FullName] FROM [ UserProfiles] >
< / asp:SqlDataSource >
< / asp:Panel >
< asp:ModalPopupExtender ID = MPEUserList RUNAT= server TargetControlID = SelectUserBtn PopupControlID = Pnl OkControlID = OKBtn BackgroundCssClass = ModalBackground DropShadow = true CancelControlID = CancelBtn >
< / asp:ModalPopupExtender >
ConnectionStrings:sos_dmsConStr %>" SelectCommand="SELECT [UserId], [FullName] FROM [UserProfiles]"> </asp:SqlDataSource> </asp:Panel> <asp:ModalPopupExtender ID="MPEUserList" runat="server" TargetControlID="SelectUserBtn" PopupControlID="Pnl" OkControlID="OKBtn" BackgroundCssClass="ModalBackground" DropShadow="true" CancelControlID="CancelBtn"> </asp:ModalPopupExtender>
我的代码落后:
my code behind:
protected void OkBtn_Click(object sender, EventArgs e)
{
UserId.Text = SourceList.SelectedItem.Value;
UserName.Text = SourceList.SelectedItem.Text;
}
嗨朋友,
请使用下面的javascript函数试试上面的内容。
$ / b
函数Sayok(){
var dpt = document.getElementById(SourceList);
alert(dpt.options [dpt.selectedIndex] .value);
document.getElementById(UserId)。innerHTML = dpt.options [dpt.selectedIndex] .value;
}
进入按钮ok调用js
这里是代码
< asp:button id =OKBtnrunat =servertext =添加用户onclientclick =Sayok(); onclick =OkBtn_Clickxmlns:asp =#unknown>
Hi Friend,
Please try the above by using bellow javascript function.
function Sayok() {
var dpt = document.getElementById("SourceList");
alert(dpt.options[dpt.selectedIndex].value);
document.getElementById("UserId").innerHTML = dpt.options[dpt.selectedIndex].value;
}
into the button ok call js
here is the code
<asp:button id="OKBtn" runat="server" text="Add User" onclientclick="Sayok();" onclick="OkBtn_Click" xmlns:asp="#unknown">
OkControlID阻止了回发。我刚删除它,现在可以正常工作。
It was the OkControlID that was preventing postback. I just removed it and it works now.
这篇关于从列表框控件中的选定项填充标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文