logo
down
shadow

Fill multiple textboxes after selecting a data from DropDownList in ASP.NET


Fill multiple textboxes after selecting a data from DropDownList in ASP.NET

Content Index :

Fill multiple textboxes after selecting a data from DropDownList in ASP.NET
Tag : chash , By : user107506
Date : December 01 2020, 05:00 PM

I hope this helps . I have a DropDownList that is linked to a SQL database. It currently shows a list of CardCode. I am trying to make it so that once a CardCode is selected, multiple textboxes are automatically filled (such as CardNum, CntctPerson,ListNum etc). I am able to automatically fill the "CardCode" and CardNum textbox as the value is the one selected but it show the First row in the database,I want to show the related row to the CardCode, I do not know how to fill the other rows that is related to the selected CardCode .How can i do this? In Advance , Replace below code in your code behind code:
DropDownList1.DataValueField = "CardCode";

SqlCommand theCommand = new SqlCommand("SELECT CardCode, CardName, Address, CntctPrsn FROM OCRD where CardCode=@CardCode ", connection);
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="StackOver._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
    Welcome to ASP.NET!
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
        onselectedindexchanged="DropDownList1_SelectedIndexChanged">
    </asp:DropDownList>

</h2>
<p>
    <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
</p>
<p>
    <asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox>
</p>
<p>
    <asp:TextBox ID="TextBox3" runat="server" ></asp:TextBox>
</p>

<p>
    <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</p>

Comments
No Comments Right Now !

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

Share : facebook icon twitter icon

How can I fill textboxes using dropdownlist without postback?


Tag : asp.net , By : alexandruz
Date : March 29 2020, 07:55 AM
To fix this issue In the microsoft Ajax control toolkit there's a ComboBox which gives DropDownList and TextBox functions enabling choosing from the ComboBox or writing directly like a TextBox. Also enables limitting independent writing only to items in the ComboBox or entering nonexisting items.

Fill GridView with TextBoxes and Dropdownlist from DataTable


Tag : chash , By : helloedwin
Date : March 29 2020, 07:55 AM
Hope this helps The DataField attribute in the bound field must equal to the column name in the datatable. For binding textboxes in the template field you can use the Eval or Bind Method.
Example:
<asp:TemplateField HeaderText="procesVerbal">
 <ItemTemplate>
     <asp:TextBox ID="tbNr" Text='<%# Eval("ColumnName") %>' runat="server"></asp:TextBox>
 </ItemTemplate>
</asp:TemplateField>  
<asp:TemplateField>
     <ItemTemplate>
        <asp:DropDownList ID="ddl" runat="server"  DataSourceID="SqlDataSource1" DataTextField="ProductName" DataValueField="ProductID" ></asp:DropDownList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT [ProductName], [ProductID] FROM [Alphabetical list of products]"></asp:SqlDataSource>
     </ItemTemplate>
</asp:TemplateField>
protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
{

    if(e.Row.RowType == DataControlRowType.DataRow)
    {           
        TextBox t = (TextBox)e.Row.FindControl("ControlID"); 
        t.Text = "Some Text";
    }

Fill multiple textboxes after selecting from a DropDownList in ASP.NET


Tag : chash , By : user134570
Date : March 29 2020, 07:55 AM
Hope that helps I would highly recommend that you use the CustomerID or equivalent ID field in the database as the DataValueField in your drop down list, as you may want to allow the same customer name in the database, but be able to tell them apart by ID.
Instead, try this:
SqlDataAdapter adapter = new SqlDataAdapter("SELECT CustomerName, CustomerID FROM Customers.dbo.Customer", connection);
adapter.Fill(customers);
DropDownList1.DataSource = customers;
DropDownList1.DataTextField = "CustomerName";
DropDownList1.DataValueField = "CustomerID";
DropDownList1.DataBind();
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    string selectedID = DropDownList1.SelectedItem.Value;

    SqlCommand theCommand = new SqlCommand("SELECT * FROM Customers.dbo.Customer WHERE CustomerID = @CustomerID", connection);
    theCommand.Paramters.AddWithValue("@CustomerID", selectedId);
    theCommand.CommandType = CommandType.Text;

    using (SqlDataReader theReader = theCommand.ExecuteReader())
    {
        if (theReader.HasRows)
        {
            // Get the first row
            theReader.Read();

            // Set the text box values
            CustomerName.Text = theReader.GetString(0);
            ...
        }
    } 
}

fill the textboxes with selecting dropdownlist in mvc


Tag : chash , By : Dave M
Date : March 29 2020, 07:55 AM
seems to work fine I want to fill textboxes which take data from database. When I select any value using dropdownlist, I need to get ID from dropdownlist and I call a function which fill @Html.EditorFor(model => model.taskName). The page musn't change. How is it possible? , Make your dropdown like this:
@Html.DropDownList("jobID", null, new {@id="job"})
@Html.EditorFor(model => model.taskName, new {@id="taskname"})
$('select#job').change(function(){

var JobId =$(this).val();


// Send Ajax call and get Task name

var Url = 'http://example.com/Controller/Action/?jobid='+JobId ;

$.ajax({
         url:    Url ,
         success: function(result) {
                     $('input#taskname').val(result); 
                  },
         error: function(error) {
                     alert(errorss); 
                  }

    });     


});

Fill multiple textboxes after selecting two columns DropDownList in ASP.NET


Tag : chash , By : user179863
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I have a DropDownList which contains the two columns one is CardCode and other is CardName and that is linked to a SQL database. It currently shows a list of CardCode + List of Cardname. I am trying to make it so that once a CardCode + CardName is selected from the two columns dropdownlist, multiple textboxes are automatically filled (such as CardNum, CntctPerson,ListNum etc). I am able to automatically fill the data from selecting only CardCode now I want to show the related row to the CardCode + CardName dropdown list, I do not know how to fill the other rows by selecting 2 column's dropdown list(CardCode + CardName) .How can i do this? In Advance ,
Code behind Code.
 protected void LoadOptions()
    {
        DataTable CardCode = new DataTable();

        SqlConnection connection = new SqlConnection("my connection string");
        using (connection)
        {
            SqlDataAdapter adapter = new SqlDataAdapter("SELECT CardCode,CardName, Address, CntctPrsn FROM OCRD", connection);

            adapter.Fill(CardCode);
            if (CardCode.Rows.Count > 0)
            {
                for (int i = 0; i < CardCode.Rows.Count; i++)
                {
                     id = CardCode.Rows[i]["CardCode"].ToString();
                     name = CardCode.Rows[i]["CardName"].ToString();
                     newName = id + " ---- " + name;
                     DropDownList1.Items.Add(new ListItem(newName,id));
                }
            }
        }
    }
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="StackOver._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
    Welcome to ASP.NET!
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
        onselectedindexchanged="DropDownList1_SelectedIndexChanged">
    </asp:DropDownList>
</h2>

       <br />
    <br />
<p>
    &nbsp;</p>
<p>
    &nbsp;</p>
<p>
Business Partner Code :&nbsp; 
    <asp:TextBox ID="TextBox1" runat="server" Width="192px" ></asp:TextBox>
</p>
<p>
Business Partner Name :
    <asp:TextBox ID="TextBox2" runat="server" Width="192px" ></asp:TextBox>
</p>
<p>
 Address :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    <asp:TextBox ID="TextBox3" runat="server" Width="196px" ></asp:TextBox>
</p>

<p>
Contact Person Name :&nbsp; 
    <asp:TextBox ID="TextBox4" runat="server" Width="196px" ></asp:TextBox>
</p>

 <p>
    <asp:TextBox ID="TextBox5" runat="server" ></asp:TextBox>
</p>
 <p>
    <asp:TextBox ID="TextBox6" runat="server" ></asp:TextBox>
</p>
 <p>
    <asp:TextBox ID="TextBox7" runat="server" ></asp:TextBox>
</p>
Related Posts Related QUESTIONS :
  • 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
  • "The attribute names could not be inferred from bind attribute 'bind-value'" exception in Blazor
  • How to fix ''System.ArgumentException" in c#?
  • C#. Ref returning delegate for ref extension method
  • Swashbuckle Swagger generate an actual guid
  • Trying to make thousands of database calls simultaneously - they stack instead of running concurently
  • run mstest from cmd using testcontainer
  • How to make M:N (many-to-many) relationship where both M and N are the same entities?
  • Consume COM DLL from multiple clients
  • Convert json string response representing UCHAR array to Byte array
  • Why does this LinqPad program produce different results on the second run?
  • ServiceStack how to use MaxLoginAttempts feature
  • What does "late-bound access to the destination object" mean?
  • How to load appsettings.json inside a Static class based on deploy environment so that I can use in other class librarie
  • dynamically add images to view
  • Are static extension methods on User object safe?
  • Process thousands of database calls simultaneously
  • Trying to decrypt a string with public key(not private) using bouncycastle in .net
  • How to retrieve the name of an usb device
  • Query many-to-many related data using Entity Framework Core
  • ASP.NET MVC : how to find the view from a controller?
  • Inconsistent behaviour using Entity Framework for ASP.NET MVC app vs windows service
  • AutoFixture Customize vs Build
  • How to change textbox location at the click of a mouse in live mode?
  • How can I deserialize a XML file without defining the parent node?
  • asp.net core how decrease class coupling
  • ASP.NET Core Razor Pages Routing With parameters
  • String Escaping With $ Interpolation and @ Encoding
  • ConfigurationManager in ASP.NET WebAPI tested with HttpServer
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com