logo
down
shadow

Multiple DropDownList but same action


Multiple DropDownList but same action

Content Index :

Multiple DropDownList but same action
Tag : chash , By : esimran
Date : November 23 2020, 01:01 AM

this one helps. I have two DropDownList with OnSelectedIndexChanged="SelectedIndexChanged" but I need to know in the C# code withch one is the one I used. , The general form for an event handler is:
OnSomeEvent(object sender, EventArgs e)
private void SelectedIndexChanged(object sender, EventArgs e)
{
    DropDownList the_list_that_changed = (DropDownList)sender;

    int ids = the_list_that_changed.SelectedIndex;
}

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

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);
});

Tag : asp.net-mvc , By : Jouni
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?


Tag : asp.net-mvc , By : Elwillow
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;
        }
    }
}
Related Posts Related QUESTIONS :
  • c# wpf | create complex object with user-defined name to Serialize into JSON
  • How can I get a instance of a generic list with reflection?
  • WPF XAML - Design time and visibility of textbox
  • EF Core and MySql query is too slow
  • Getting Registered App Display Name from an App Id
  • How to get all variables from a string
  • Delete entity with all childs connected
  • Azure Build agent cant´t find class library referance
  • Initialize Nested Dictionaries in c#
  • .Net Core Binding
  • Generic event test method, preventing code duplication
  • How do I keep the ellipses in the center when the screen is resized
  • How to require a property using JsonSchema.NET?
  • C# XDocument Element/Elements returns null
  • Autofac keyed service with IEnumerable relationship type
  • Installing EntityFramework via NuGet manager
  • Always Check if there is Internet Connection Xamarin forms
  • WCF OneWay service slows down when aspNetCompatibilityEnabled is set to false
  • Can we use JsonRequestBehavior.AllowGet with [HttpPost] attribute?
  • How to customize the Setup wizard with custom forms in Visual Studio setup project
  • C# ASP.NET - Use method from another class to create labels
  • C# List IList or IEnumerable as argument
  • Parsing File with C# And Replace method
  • Losing special unicode characters in encryption (C#)
  • Getting stored procedure returned value instead of row affected
  • How can I construct HTML using NameValuePair in android?
  • Loading a pop up page in ASP.net through a js file
  • How to pass alert or notification message from controller to View?
  • C# to pause, turn on ssas server, backup cube.... how to?
  • How to execute DataTable.Select() for a column of custom class type for a particular element in that C#
  • how to connect mysql8.0 with C#
  • Passing incorrect values into MultiValueConverter by MultiBinding
  • Can i use IEnumerator as Update func?
  • How to convert API Json response to C# Array?
  • Blazor Textfield Oninput User Typing Delay
  • Performing both layout and render transform results in wrong output
  • uwp beforetextchanged cursor moving in front of text
  • How to keep duplicates from a string[] exclude words from a List and print them out
  • .Net Core Strings.Asc/Mid/Chr/Len missing even after importing Microsoft.VisualBasic
  • How to return to previous search page without being asked to Confirm Form Re-submission and keeping the results on ASP.N
  • How set a identity scaffolding item/page how initial page in asp.net MVC core?
  • LINQ isn't calling Dispose on my IEnumerator when using Union and Select, expected behavior or bug?
  • What is "ByteArray.uncompress()" in AS3 equivalent to in C#?
  • Getting a specific letter from a string variable for my simple guessing game for clues
  • Send an email with Outlook without a subject --- dialog box issue
  • passing List<MyModel> from my controller in the "WebInterfaceProject" to the processor method in "D
  • How to convert Word document created from template by OpenXML into MemoryStream?
  • How can I make a single slider that changes the color of an object?
  • Remap JSON parameter in c#
  • What is the difference between "this ref" and "ref this" when talking about C# 7.2 ref extension met
  • Convert OpenSSL encryption into native C#
  • Accessing Properties in Razor Pages
  • How to get SOAP element value
  • Projection after Group
  • C# error cannot convert sytem.text.regularexpressions.match to string
  • Issues with Save/Load System in a Text Based Adventure game made with ScriptableObjects in Unity
  • VS2019 MSBuild.exe - ASP .Net MVC project fails to publish when using PublishProfile, but works when using OutDir parame
  • Does <pages validateRequest="false" /> in Web.config still matter?
  • How to send new request to redirect URL with new access token
  • Attempt to invoke virtual method on a null object reference Xamarin LockScreen
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com