ASP.NET MVC2 Dropdownlist and URL.action
Tag : jquery , By : user184406
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further A really simple way is to use the url you want to call as the value of the options in the dropdown. There are other ways to do it, but that's the most bare-bones: <select id="myList" ...>
<% foreach (var id in ids) { %>
<option value="<%= Url.Action("Action", "Controller", new { id = id }) %>">id</option>
<% } %>
</select>
$('#myList').change(function(){
$.get($(this).val(), doOnSuccess);
});
<form id="theForm" action="@Url.Action("A", "C")" method="POST">
@Html.DropDownList("paramName", theSelectListAsInTheQuestion, new { id = "theDropDown" })
</form>
...
public class CController : Controller {
[HttpPost]
public ActionResult A (int paramName) {
...
}
}
...
// and in jQuery
$('#theDropDown').change(function(event){
var f = $('#theForm');
$.post(f.attr('action'), f.serialize(), onSuccess);
});
|
Dropdownlist onchange action
Date : March 29 2020, 07:55 AM
help you fix your problem i really searched endless for my answer, and maybe my last remark did it: found the answer myzelf. First you need to define the FORM: @Using Html.BeginForm("index", "purchaseorders")
@Html.DropDownList("fOrderstatus", TryCast( ViewBag.StatusOptions, SelectList), "--pick--", New With { .title="Pick an orderstatus", .onchange="submit();"} )
End Using
Function Index(ByVal fOrderstatus As String) As ViewResult
|
How to pass multiple Html.DropDownList selected values from View( .aspx ) to MVC controller's action?
Date : March 29 2020, 07:55 AM
To fix this issue I am not really sure what you're asking here. You don't need any kind of hidden field to post the selected values of a dropdown. Your Dropdownlist code is invalid to begin with. Typically you have something like this: <%= Html.DropDownList("SemesterToOrganize", GetSemesterToOrganize()) %>
<%= Html.DropDownList("SemesterToBaseOn", GetSemesterToBaseOn()) %>
[HttpPost]
public ActionResult MyAction(string SemesterToOrganize, string SemesterToBaseOn) {
// your code.
}
public ActionResult MyAction ()
{
ViewData["SemesterList"] = // list of semesters
return View();
}
<%= Html.DropDownList("SemesterToOrganize", ViewData["SemesterList"]) %>
<%= Html.DropDownList("SemesterToBaseOn", ViewData["SemesterList"]) %>
[HttpPost]
public ActionResult MyAction(string SemesterToOrganize, string SemesterToBaseOn) {
// your code.
}
<%= Html.DropDownList("strSemesterToOrganize", (SelectList)ViewData["Semester"]) %>
<%= Html.DropDownList("strSemesterToBaseOn", (SelectList)ViewData["Semester"]) %>
|
How can I set the value of a dropdownlist according to the action of another dropdownlist?
Tag : chash , By : Nougat
Date : March 29 2020, 07:55 AM
Does that help You can set AutoPostBack="true" to your dropdownlist who define behavior of second dropdownlist, and also define SelectedIndexChanged event on this dropdownlist asp:DropDownList ID="DepartTo" runat="server" AutoPostBack="True"
onselectedindexchanged="itemSelected">
</asp:DropDownList>
protected void itemSelected(object sender, EventArgs e)
{
var control = (DropDownList)sender;
if(control.SelectedValue == "")
{
.....
}
}
|
How to make multiple DropDownList change based on selection from other DropDownList
Tag : chash , By : Alan Little
Date : March 29 2020, 07:55 AM
this one helps. While I'd thoroughly advise you to use parameterized queries, this should work for you (perhaps with minor adjustments as I can't see the entirety of your code, of course) This method should generate a valid where clause. You can use this method in the various OnSelectedIndexChanged methods in your code-behind to prevent a lot of copy/pasted code. public string GenerateWhereClause()
{
List<String> conditions = new List<String>();
conditions.Add("(CT.ACTIVESTATUS = 0)");
if (ddlTaskName.SelectedIndex > 0)
{
string strText = ddlTaskName.SelectedItem.Text;
conditions.Add(String.Format("(CT.ATTR2739 = '{0}')", strText));
}
if (ddlService.SelectedIndex > 0)
{
string strText = ddlService.SelectedItem.Text;
conditions.Add(String.Format("(CT.ATTR2846 = '{0}')", strText));
}
if (ddlStatus.SelectedIndex > 0)
{
string strText = ddlStatus.SelectedItem.Text;
conditions.Add(String.Format("(CT.ATTR2812 = '{0}')", strText));
}
if (ddlDueDate.SelectedIndex > 0)
{
string strText = ddlDueDate.SelectedItem.Text;
conditions.Add(String.Format("(CONVERT(VARCHAR(14), CT.ATTR2752, 110) = '{0}')", strText));
}
if (ddlOwner.SelectedIndex > 0)
{
string strText = ddlOwner.SelectedItem.Text;
conditions.Add(String.Format("(UA.REALNAME = '{0}')", strText));
}
if (ddlClient.SelectedIndex > 0)
{
string strText = ddlClient.SelectedItem.Text;
conditions.Add(String.Format("(CT.ATTR2799 = '{0}')", strText));
}
// You can add additional filters here. This isn't the cleanest way of doing it, but it's fairly quick and easy as long as you don't intend to add many more filters.
string conditionsJoined = String.Join(" AND ", conditions);
string whereClause = String.Format(" WHERE {0}", conditionsJoined);
return whereClause;
}
public void PullData(string sortExp, string sortDir)
{
string query = String.Format("{0}{1}", strMainQuery, GenerateWhereClause());
DataTable taskData = new DataTable();
connString = ""; //the connection string is here
using (SqlConnection conn = new SqlConnection(connString))
{
try
{
SqlCommand cmd = new SqlCommand(query, conn);
// create data adapter
SqlDataAdapter da = new SqlDataAdapter(query, conn);
// this will query your database and return the result to your datatable
DataSet myDataSet = new DataSet();
da.Fill(myDataSet);
DataView myDataView = new DataView();
myDataView = myDataSet.Tables[0].DefaultView;
if (sortExp != string.Empty)
{
myDataView.Sort = string.Format("{0} {1}", sortExp, sortDir);
}
yourTasksGV.DataSource = myDataView;
yourTasksGV.DataBind();
conn.Close();
}
catch (Exception ex)
{
string error = ex.Message;
}
}
}
|