以下代码; 代码不返回值空字符串
private void DisplayDplace()
{
BusinessLogicLayer.Businesslogiclayer objll = new BusinessLogicLayer.Businesslogiclayer();
DataSet ds = objll.Binddname();
drpfromplace.DataSource = ds;
drpfromplace.DataTextField = "dname";
drpfromplace.DataValueField = "did";
drpfromplace.DataBind();
drptoplace.DataSource = ds;
drptoplace.DataTextField = "dname";
drptoplace.DataValueField = "did";
drptoplace.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DisplayDplace();
}
}
protected void Calendar1_SelectionChanged1(object sender, EventArgs e)
{
TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["doj"] = TextBox1.Text;
Session["noofseats"] = DropDownList6.SelectedItem.ToString();
Session["fd"]= drpfromplace.SelectedItem.Value.ToString();
Session["td"] = drptoplace.SelectedItem.Value.ToString();
}
}
答案 0 :(得分:0)
如果你想获得dropdown的值,那么你将不得不使用像javascript / jquery那样的客户端脚本。如果你想获得代码背后的值,那么你需要创建一个ajax调用。
在后面的代码中创建一个webmethod:
[WebMethod]
public static string MyWebMethod(string name )
{
/your logic goes here
return ("Yeey");
}
现在在aspx.cs上创建一个Ajax调用:
$('#mybutton').on('click',function(){
$.ajax({
type: "POST",
url: "Default.aspx/MyWebMethod",
data: JSON.stringify({ name: $('#drpname').val() }),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function (data, status) {
alert("victory");
},
failure: function (data) {
alert(data.d);
},
error: function (data) {
alert(data.d);
}
});
});
答案 1 :(得分:0)
您可以向页面添加ScriptManager
并将代码包装在UpdatePanel
内。
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="A" Value="a"></asp:ListItem>
<asp:ListItem Text="B" Value="b"></asp:ListItem>
</asp:DropDownList>
<br />
<asp:Button ID="Button1" runat="server" Text="getValue" OnClick="Button1_Click" />
<br />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
背后的代码与以往一样。
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = DropDownList1.SelectedValue;
}