Results 1 to 2 of 2

Thread: DataGrid and a DropDownList

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    DataGrid and a DropDownList

    I've got a template column in a datagrid which consists of a dropdownlist. I am handling the selectedindexchanged event of the dropdownlist, no problem. But what I want to do, is this:

    If the selected index of the dropdownlist in row #7 changes, I'd like for a textbox in that same row to be enabled.

    This was easy with the DataGrid's ItemDataBound event. All I had to do was:

    Code:
    DropDownList ddl=(DropDownList)e.Item.FindControl("cmbLeaveType");
    string strLeaveType = ddl.SelectedValue.ToString();
    TextBox txtTDT = (TextBox)e.Item.FindControl("txtToDateTime");
    
    switch(strLeaveType)
    					{
    						case "LeaveWithoutApplication":
    							txtFDT.Enabled = false;
    							break;
    // and so on
    Thing is, I don't know how to access the "correct" textbox or control.

    Any guidance?

  2. #2

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: DataGrid and a DropDownList

    I hate solving my own problems.

    In the HTML, I gave a name to the OnSelectedIndexChanged handler.

    In the codebehind,

    Code:
    DropDownList ddl = (DropDownList)sender;
    			string strLeaveType = ddl.SelectedValue.ToString();
    
    			int counter;
    			DataGridItemCollection DataGridItems = dgEditLeave.Items;
    			for (counter=0; counter<DataGridItems.Count; counter++) 
    			{
    				DropDownList ddl1 = (DropDownList)DataGridItems[counter].FindControl("cmbLeaveType");
    				if(ddl1 != null)
    				{
    					if (ddl.ClientID ==  ddl1.ClientID)
    						break;
    				}
    			}
    			
    			TextBox txtTD = (TextBox)dgEditLeave.Items[counter].FindControl("txtTotalDays");
    			//dgEditLeave.Items[counter].FindControl("");
    			
    			if (strLeaveType=="CompensatoryOff")
    			{
    				txtTD.Enabled = false;
    				txtTD.Text = "HELLO";
    			}
    And uhm... that's it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width