Visual Studio .NET - Another problem I ran to

Asked By Jesse Gomez on 09-Dec-05 12:31 PM
Ok I have 9 fields
field 9 text is Status and I have a droplistbox with the ID="dropdown" with two values
Open, Close
and I get this error message when I try updating it
http://www.badongo.com/file.php?file=dropdownerror__2005-12-09_updaterror.bmp
does these mean I need to change the name to TextBix to dropdown???
please help thx alot!

Change to DropDown

Asked By F Cali on 09-Dec-05 12:35 PM
Hi Jesse,
Since it's a dropdownlist control, you have to change the casting of the control from TextBox to DropDownList.

I do this

Asked By Jesse Gomez on 09-Dec-05 12:42 PM
string status = ((DropDownList)e.Item.Cells[9].Controls[0]).Text;
gives me an error ?

I get this error message

Asked By Jesse Gomez on 09-Dec-05 12:44 PM
Specified cast is not valid. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error: 
Line 102:			string serialnumber  = ((TextBox)e.Item.Cells[7].Controls[0]).Text;
Line 103:			string storenumber  = ((TextBox)e.Item.Cells[8].Controls[0]).Text;
Line 104:            string status = ((DropDownList)e.Item.Cells[9].Controls[0]).Text;
Line 105:			
Line 106:    
Source File: c:\inetpub\wwwroot\gssquarantines\quarantines.aspx.cs    Line: 104 
Stack Trace: 
[InvalidCastException: Specified cast is not valid.]
   gssquarantines.WebForm1.datagrid_UpdateCommand(Object source, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\gssquarantines\quarantines.aspx.cs:104
   System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs e) +109
   System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e) +507
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
   System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e) +106
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +121
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +115
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138
   System.Web.UI.Page.ProcessRequestMain() +1277
Use SelectedItem Text
Asked By F Cali on 09-Dec-05 12:45 PM
Since this is a drop down list, you should use the SelectedItem.Text property:
string status = ((DropDownList)e.Item.Cells[9].Controls[0]).SelectedItem.Text;
Earlier
Asked By Jesse Gomez on 09-Dec-05 12:49 PM
Hey bro earlier you asked me for this page
http://g.1asphost.com/diosdivino/myasppage.htm
I still get the out of index error message please help me out thanks alot
.
I wanna resize all the fields thx!
ok my new code looks like this
Asked By Jesse Gomez on 09-Dec-05 12:52 PM
private void datagrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
int ID = (int) datagrid.DataKeys[(int) e.Item.ItemIndex];
tring datereceived = ((TextBox)e.Item.Cells[1].Controls[0]).Text;
string unitmanufacturer = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
string firstname = ((TextBox)e.Item.Cells[3].Controls[0]).Text;
string lastname = ((TextBox)e.Item.Cells[4].Controls[0]).Text;
tring airwaybill = ((TextBox)e.Item.Cells[5].Controls[0]).Text;
string unitmodel = ((TextBox)e.Item.Cells[6].Controls[0]).Text;
string serialnumber  = ((TextBox)e.Item.Cells[7].Controls[0]).Text;
string storenumber  = ((TextBox)e.Item.Cells[8].Controls[0]).Text;
string status = ((DropDownList)e.Item.Cells[9].Controls[0]).SelectedItem.Text;
string sql = 
"UPDATE records SET DateReceived='" + datereceived + 
"', UnitManufacturer='" + unitmanufacturer + 
"', FirstName='" + firstname + 
"', LastName='" + lastname + 
"', AirwayBill='" + airwaybill + 
"', UnitModel='" + unitmodel + 
"', SerialNumber='" + serialnumber + 
"', StoreNumber='" + storenumber + 
"', Status='" + status +
"' WHERE ID=" + ID.ToString(); 
			ExecuteNonQuery(sql);
			datagrid.EditItemIndex = -1 ;
			ReadRecords();
		}
and I still get this error message when I hit the Update link
Specified cast is not valid. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error: 
Line 102:			string serialnumber  = ((TextBox)e.Item.Cells[7].Controls[0]).Text;
Line 103:			string storenumber  = ((TextBox)e.Item.Cells[8].Controls[0]).Text;
Line 104:            string status = ((DropDownList)e.Item.Cells[9].Controls[0]).SelectedItem.Text;
Line 105:			
Line 106:    
Source File: c:\inetpub\wwwroot\gssquarantines\quarantines.aspx.cs    Line: 104 
Stack Trace: 
[InvalidCastException: Specified cast is not valid.]
   gssquarantines.WebForm1.datagrid_UpdateCommand(Object source, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\gssquarantines\quarantines.aspx.cs:104
   System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs e) +109
   System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e) +507
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
   System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e) +106
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +121
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +115
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138
   System.Web.UI.Page.ProcessRequestMain() +1277
please help me on the width
Asked By Jesse Gomez on 09-Dec-05 01:36 PM
wehn I edit the width on the text box is too long
Basically this means that
Asked By Aarthi Saravanakumar on 09-Dec-05 02:36 PM
string status = ((DropDownList)e.Item.Cells[9].Controls[0]).SelectedItem.Text; 
e.Item.Cells[9].Controls[0] is not of type Drop DownList
print 
string status = (e.Item.Cells[9].Controls[0].GetType());
And see what the type of the control is first...
Updated Code
Asked By F Cali on 09-Dec-05 11:22 PM
Hi Jesse,
Try this:
string serialnumber = ((TextBox)e.Item.Cells[7].Controls[0]).Text; 
string storenumber = ((TextBox)e.Item.Cells[8].Controls[0]).Text; 
string status = ((DropDownList)e.Item.Cells[9].Controls[0]).SelectedItem.Text;
DropDownList?
Asked By F Cali on 10-Dec-05 12:27 AM
Hi Jesse,
Are you sure that the control in Cell 9 is a drop down list and not a text box or a list box?  If it is a list box, you can use the following:
string status = ((ListBox)e.Item.Cells[9].Controls[0]).SelectedItem.Text;
How are you changing the type of control for the Status column?  Can you post the code and the page as well.
well
Asked By Jesse Gomez on 10-Dec-05 12:48 AM
I will see if I can figure it out if I have problmes I will botify you thx alot though.
help
ASP.NET Dynamic TextBox & DropDownList Control ViewState To Store NameValueCollection This article demonstrates the ASP.NET page life cycle, dynamic how this can be accomplished. In a nutshell, I've extended the existing ASP.NET TextBox server control by adding a custom made namevaluecollection class and overrode how ViewState is handled with the control. For your convenience, I've hard coded the base properties of the textbox and dropdownlist control that can be stored in ViewState. These properties are not stored in ViewState by hook up the existing ViewState for the control with the same ID. Thus, with the exception of our events, everything including fonts, colors, styles, values, etc. . . is automatically reinitialized to our controls to our html table. So far, I've only created custom versions of the TextBox and DropDownList controls. I think you'll find that it would be pretty easy to create different
hi guys, I hav ADMIN_ID textbox and ROLES dropdownlist, when I enter ADMIN_ID such as staff001 then at ROLES dropdownlist I must select "staff" else display an error msg, for example staff002 with roles manager it will be a normal IF else condition: if (txtAdmin_ID.Text = = "staff001" OR etcc) { if(dropdownlist.seleteditem.value = = "staff) { / / do validation here } else { / / do validation if not staff here } } Thanks Hi selectQuery , conn)) { Lable1.Text = Convert.ToString(cmd.ExecuteScalar()); Dropdown1.SelectedText = Convert.ToString(cmd.ExecuteScalar()); } } } catch (Exception ex) { MessageBox.Show( "Invalid ID" ); } Put the above code on textchange event of textbox where you are putting Admin_ID Hope this will help you If I enter ADMIN_ID "staff005
Hi Friends, I have a D ropdownlist select the other value from list (Dropdown) , Dropdoenlist Enable property will be false and One TextBox (textbox ID = "txtBCategory") will be visible. I enter some value into this TextBox . till everything is fine. But problem occurred when I press Save button. The value which I enter in textBox or selected from Dropdownlist it was not save in database. I am Sending my Code: using System; using System record inserted successfully."; else lblMessage.Text = "Value can't insert, contact to your Administrator"; } catch (Exception ee) { lblMessage.Text = ee.Message.ToString(); } finally { Reg = null; } subClear(); } private DataTable subBsCategory() / / Fill the dt.Rows.Count; rowN++) { ddlBusnessCategory.Items.Add(new ListItem(dt.Rows[rowN]["CategoryName"].ToString())); } } catch (Exception ee) { lblMessage.Text = ee.Message.ToString(); } finally { gen = null; } return dt; } protected void ddlBusnessCategory_SelectedIndexChanged(object
Hi, In a gridview, im having columns - Textbox, Dropdownlist, Button When i enter some value in textbox and click the corresponding row Button, the textbox value should be added to the dropdownlist items. Can anybody help me in this regard. Thanks. hi. . here i sthe code. . Find the button Button button = ( Button )sender; / / Find parent row GridViewRow parentRow = ( GridViewRow )button.NamingContainer; / / find DropDownlist and textbox DropDownList ddl = parentRow.FindControl( "ddlSpecificationAttributeOption" ) as DropDownList ; TextBox txtCustom1 = parentRow.FindControl( "txtCustom1" ) as TextBox ; if
with 8 columns abt employee's travel information. gridview will contain empty textboxes in and dropdownlist in a row and their are multiple such rows and client will type data to 284775" / > <Columns> <asp:BoundField DataField = "SerialNo." HeaderText = "Serial No." / > <asp:TemplateField HeaderText = "Source"> <ItemTemplate> <asp:DropDownList runat = "server" ID = "dropdownsource" DataSourceID = "SqlDataSource2" DataTextField = "CityName" DataValueField = "CityId" AutoPostBack = "True"> < / asp:DropDownList> < / ItemTemplate> < / asp:TemplateField> <asp:TemplateField HeaderText = "Source Date"> <ItemTemplate> <asp:TextBox ID = "txttodate1" runat = "server" Text = '<%#Eval("ToDate")%> '> < / asp TextBox> <asp:CalendarExtender ID = "CalendarExtender1to" runat = "server" PopupButtonID = "imgto" Format = "dd-MMM-yyyy" TargetControlID = "txttodate1"> < / asp ImageUrl = "~ / css / images / cal.png" / > < / td> < / ItemTemplate> < / asp:TemplateField> <asp:TemplateField HeaderText = "Destination"> <ItemTemplate> <asp:DropDownList runat = "server" ID = "dropdowndest" DataSourceID = "SqlDataSource2" DataTextField = "CityName" DataValueField = "CityId" AutoPostBack = "True"> < / asp:DropDownList> < / ItemTemplate
class written by one of my coworkers. All of the columns are TemplateColumns. The columns: - -- -- -- -- -- -- -- - TextBox TextBox DropDownList ParentDropDownList ChildDropDownList (dependant on the ParentDropDownList) DropDownList TextBox TextBox Button Bound (this holds the ID) After the page initially loads I can click the DataGrid columns / / - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - private void InitializeDataGrid(){ _gridTypes = new ArrayList(5); _gridTypes.Add(new GridDataTypes(GridDataTypes.Control.TextBox, "linkName", "Link Text", "LinkText", "", "LinkText", "", "Left")); _gridTypes.Add(new GridDataTypes(GridDataTypes.Control.TextBox, "linkURL", "URL", "LinkURL", "", "LinkURL", "", "Left")); _gridTypes.Add(new GridDataTypes(GridDataTypes.Control.DropDown, "ddlLinkType", "Link Type
code is string str1 = ConfigurationManager.ConnectionStrings["AppConnectionString1"].ConnectionString; SqlConnection con1 = new SqlConnection(str1); con1.Open(); DropDownList d = new DropDownList(); d = (DropDownList)gdview1.FindControl("DropDownList"); TextBox t1 = new TextBox(); t1 = (TextBox) gdview1.FindControl("Textbox"); SqlCommand cmd2 = new SqlCommand("UPDATE ScheduleInterview SET Status = '"+t1.Text+"'where Id = 1 ", con1); cmd2
Hi, I have a GridView in which each row consists of DropDownList and TextBox. I also have a "Add Row" button. Now when i click this "Add Row" button a new row gets added with a dropdownlist and an empty text box. I will select a value "One" from dropdownlist and enter a value "1" in the textbox.Now if i click "Add Row" button again to add a new row, the first i added is losing its values "One" and "1".So it is now displaying a dropdownlist and an empty textbox again. Is there any way to restore the values of the dropdownlist and textbox after
ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] I have one Login Form which contains useriD(textbox), password(textbox), role(in role we have two type of Employees one is User and other reporting dropdown control is used and login button and one employee Profile Form which contains EmpID(textbox), Empname(textbox), MysiteURL(textBox), Reporting officer(textbox), E-mail(textbox) and Resume(file upload control) and edit button is used EmployeeView Form which contains Radio view button EmpTechExp Form which contains four columns like Technology(dropdown), Skill Level(Dropdown), Duration (textbox)in months, efficiency(dropdown) and we have 5 rows like this and each row contains