.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

if 'other' from drop down is selected, the respective details textbox is now validated using a req

Posted By:      Posted Date: September 02, 2010    Points: 0   Category :ASP.Net
Hi, I'm developing a system with a number of drop down lists. One of the questions relates to the light conditions at the time of the incident (for example, it could be dark, poorly lit, dusk etc...)One of the options on the drop down list is 'other'. (i argue with my client that if they're using dropdown lists, don't use other, but they disagree)The next field is 'If other, please give details'. What i'm basically looking to acheive is to say that if you select 'other' from the dropdown list, the 'if other' field becomes required using a requiredfield validator. (and the reverse too, so if you choose a pre-poulated answer such as 'dusk', the 'if other' field is not required.)I have all my other validations working fine and my drop down list is populated from an SQLDatasource (not ASP.net Items)My dropdown list id= ddlLightMy 'other' field id= txtbxLightOtherMy required validator for the 'other' field id= requiredvalLightOthermy sqldatasource id= sqldatasourcelightI'm thinking something like this, but it's not quite working for me:If ddlLight.Text = ("other") Thentxtbxlightother...Any assistance would be great. I've done this before and i'nm frustrating myself as i can't seem to work it out!ThankMike

View Complete Post

More Related Resource Links

Retain DropDown,TextBox's previously selected values after redirected from another page.


 Hi People, How are you all doing?

I have 2 pages one is SearchPage & It has DropDowns, textboxes to specify the search criteria. From the search result the user is redirected to another page when he clicks the hyperlink in the search result  where he fills in the information and again redirected to SearchPage. Now the SearchPage is posted back with no state i just want to retain the search criteria and display when user comes back. Please give me some suggestion how to get this done. I've used ViewState to save the values and check them in Page_Load but they are null.   



 Update: I've come up with this code. But the problem is The values are being retained but the Button_Click event is not being handled properly. When i Check the code even after this "DropDownList1.SelectedValue = Session["Name"].ToString();" DownList1.SelectedValue is EMPTY"" samw with DropDownList2 . please Suggest something


    protected void Page_Load(object sender, EventArgs e)
        if (IsControlsEmpty())
            if (SessionExist())
                DropDownList1.SelectedValue = Session["Name"].ToString()

Getting Details from "Selected" Files.

I'm working on a program that uses the OpenFileDialog class for users to select 2 program Exes. The idea behind it is I want them to be able to connect to a MySQL db and check their versions against the current one. How can I collect data from the selected exe file such as the version of the file. Many programs have a File Version that I want to read off of. Is this even possible; or should I be doing this a different way?

Button to copy selected item in dropdown to textbox

Hi, I found this bit of code which I tried and it isn't working. I just want to place a button next to a dropdown, and when clicked, the selected item in the dropdown will put into another textbox. <head><title>Untitled</title></head><body><script type="text/javascript">function copy() {var sel = document.getElementById("names");var text = sel.options.value;var out = document.getElementById("output");out.value += text+"\n";}</script> <select id="names"><option>Product One</option><option>Product Two</option><option>Product Three</option><option>Product Four</option></select><input type="button" onclick="copy()" value="Copy"><textarea id="output"></textarea> </body></html>   I saved this as a file and opened it in IE to test and nothing went into the textarea. Also i tried it in Firefox and the textarea said undefined each time I click the button. Can someone help to get this working?

how to in Insert database NULL if drop down list item is not selected ?

hi,   on my aspx I have the below DDL   <asp:DropDownList ID="ColorDDL" runat="server" DataSourceID="ColorObj"                                                 DataTextField="Size" DataValueField="BustId" Width="150px"                                                 AppendDataBoundItems="True">                                                    <asp:ListItem Value="-1">(Optional)</asp:ListItem>                             &n

How to get selected text of a drop down list in MVC?

I aggressively googled around, but could not find the information I am looking for.  I know how to populate a dropdownlist using my view model and Html.DropDownListFor helper method.Suppose the drop down list contains U.S. stateId and stateName key value pairs.  Suppose my ViewModel looks likepublic class MyViewModel{      public IList<State> States {get; set;}      public int SelectedStateId {get; set; }}public class State{     public int StateId {get; set; }     public string StateName {get; set; }}Now, in my controller's action method:[HttpPost]public ViewResult Index(MyViewModel  myViewModel){     // This following line seems to work fine, myViewModel automatically      // picks up the selected item of the drop down list.  How does this work?      // Is this the so-called model binding?      int selectedStateId = myViewModel.SelectedStateId;      // But, then, how do I get the selected state name?     string stateName = ??????????????     ... ... }Do I have to change my implementation of my view model?  In any case, how to get the selected item text of the drop down list?  Any hint?  Thanks a lot.

need to get the value selected in the combo box to a textbox

When i select or autosuggest in a combo box , i should be able to get the selected value in a text box in the client side using ajax without a postback.        

How to apply color to selected number of items in check box list and drop downlist

Hi all,    I want to apply color to selected number of items in checkbox list and seleted number of items in drop downlist for e.g color red for few items and black (default). I have a bit value set in data base so if bit is set to 0 then red and if 1 then back. Please help me.  

pass Drop down selected value to Texxtbox in SSRS Reports

hi, i have developed a ssrs report which as Two dropdown as parameter first one is used to select the Starting year second one is used to select the ending year based upon the selected value a table will retreive data's Above the table there s textbox which is used to give message as "Project From year 2006-2007 " this 2006-2007 must be the dropdown selected how to do this? Thanks, Saraswathy

How do I drop a drop down box into a details view ?

SO I've got a Details View control which I can insert data into my database with OK.However, in one of the text fields I want to limit what the user can insert to a set of key words. So the obvious thing to do is to present the User with a drop down box to select a key word.So I have converted the text field into a template and I thought I could replace the <InsertItemTemplate> in the details view with the drop down box. Well it looks like what I want but when I INSERT the data that field is not inserted into the database.So I guess I need to Bind the Drop Down somehow to the Insert - How do I do that ?My code is below; <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" AutoGenerateRows="False" DataKeyNames="dateID" DataSourceID="SqlDataSource1" DefaultMode="Insert"> <Fields> <asp:BoundField DataField="dateID" HeaderText="dateID" InsertVisible="False" ReadOnly="True" SortExpression="dateID" /> <asp:TemplateField HeaderText="diaryDate" SortExpression="diaryDate"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<

Add selected CheckBox Row details in Second GDView & remove from second GDView onUncheck

i hv two gridviews first is overview of Requisition and second of Requisition Details
In First GDView I have the requisition columns for checkBox , added by following code

DataGridViewCheckBoxColumn dataGridViewCheckBoxColumnObject = new DataGridViewCheckBoxColumn();
dataGridViewCheckBoxColumnObject.Name = "Select";
dataGridViewCheckBoxColumnObject.Width = 60;

In first GDView I have another column of RequisitionID's

How should I loop through the GDView to get the RequisitionID's of selected rows????

I want to add the details of that requisition in Second GDView as soon as I Checked/Click on the CheckBox of First GDView. Also to remove the Requisition Details as soon as I Remove/Uncheck the CheckBox of first GDView

Can anyone help me

Thank you

Drop Down List Selected Value problem ...



I created an Html Helper that renders 3 drop down lists (Day, Month and Year) for a field of type DateTime:

    public static MvcHtmlString Date(this HtmlHelper htmlHelper, String name, IEnumerable<SelectListItem> days, IEnumerable<SelectListItem> months, IEnumerable<SelectListItem> years, IDictionary<String, Object> htmlAttributes) {

      if (String.IsNullOrEmpty(name)) throw new ArgumentNullException("name", "Name cannot be null");

      StringBuilder fields = new StringBuilder();

      if (days != null)
        fields.Append(htmlHelper.DropDownList(String.Format("{0}.Day", name), days, String.Empty, htmlAttributes));

      if (months != null)
        fields.Append(htmlHelper.DropDownList(String.Format("{0}.Month", name), months, String.Empty, htmlAttributes));

      if (years != null)
        fields.Append(htmlHelper.DropDownList(String.Format("{0}.Year", name), years, String.Empty, htmlAttributes));

      return MvcHtmlString.Create(fields.ToString());     

    } // Date

And I have a DateFor extension:

    public static MvcHtmlString DateFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IEnumerable<S

Howto add selected item from dropdownlist to a textbox on the same form?


 I have been trying to figure out what the proper method is to be able to have a dropdownlist on the same form that holds a number of textboxes for properties. I am using a strongly typed typed view which was generated by the Visual Studio IDE so it contains textboxes for all of the properties of my strongly typed class.  The class has a few properties that can have a set of possilbe answers; I'd like to displat those possible answers in a dropdownlist and then when the user fills in the form and clicks the submit button the selected item would be transferred to the correct property. I have a solution but think there must be a better solution out there and was wondering if anyone might point me in the right direction.

So say I have a model with 3 properties, FirstName, LastName. and MaritalStatus.

If I generated a view for this then I'd get an aspx file with the following:


    <% using (Html.BeginForm()) {%>
        <%: Html.ValidationSummary(true) %>

            <div class="editor-label">
                <%: Html.LabelFor(model => model.FirstName) %>

Details should be display gridview's TextBox


Dear Friends,
   I am using gridwiew.
  To display Name, Sex, DOB, and Message(From SQL-server 2005)
   I want The message coloumn datails should be display in textbox(textbox placed in inside the gridwiew) 

How can I get the selection from drop'dn into the textbox. Thanks



 <asp:BoundField DataField="QtyReceived" HeaderText="QtyReceived" SortExpression="QtyReceived" />
                <asp:TemplateField HeaderText="Description" SortExpression="Description">
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
                                 <asp:DropDownList ID="DropDownList5" Width="50%" Style="height: 20px; width: 300px"
            runat="server" AppendDataBoundItems="true" DataSourceID="AccessDataSource7" SelectionMode="multiple"
            DataTextField="Description"  DataValueField="DollarValue">

How do I pass the Selected Value of my Drop Down List


I added 3 values on DropDownList controls. ID= DropDownList1. If a user selects a value from the DropDownList, I'd like to insert the value on my DB (DB = Test) and in Column (Column = LastName). Below is the code I get when I double click on the DropDownList.


Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged



Drop down remove selected item on post back


Hi ,i have a place order form and i have a drop down list that contains list of items

whenever i add item (for example item1)  to place order and click add another item button,

i need to remove  (item1 ) from drop down list to avoid dupplicate insert in sql table

or mayb need to fill the drop down but without (item1) cause i already selected it

it s kind of validation

i am using sql datasource to fill the drop down list of items

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend