I set a textbox visible = false on a textbox that just holds a value. When trying to convert that value and then in开发者_Python百科put it into a query it fails in visible=false. What is the proper way to do this since this obviously is not it. HEre is the code that passes the two textbox values to the query.
private void cmdAddAdd_Click(object sender, EventArgs e)
{
DataClasses1DataContext db = new DataClasses1DataContext();
int interestsKey;
interestsKey = Convert.ToInt32(interestsKeyTextBox.Text);
InterestAdd newAdd = new InterestAdd();
newAdd.CaseNumberKey = caseNumberKeyTextBox.Text;
newAdd.InterestsKey = interestsKey;
db.InterestAdds.InsertOnSubmit(newAdd);
db.SubmitChanges();
LoadCaseNumberInterestsKey(interestsKey, newAdd.CaseNumberKey, false, "interestAdd");
this.interestAddDataGridView.EndEdit();
this.interestAddDataGridView.Refresh();
}
I set the textbox behavior to visible = false.
Thanks,
Kor
You can use these alternatives:
- Make your textbox enable to false (if you don't want user to modify it)
- Use a label and set its forecolor and backcolor same (which makes it invisible)
Keep your textbox visible = ture and set its height and width to ZERO.
Because you are setting the visibility to false, the textbox is not included in the form element and therefore will never be posted. If you don't care about seeing the contents of the textbox just use a hidden input. If you want to see the contents of the textbox, but don't want it to be changed you can use the readonly attribute of the textbox and set it to true. This will post the value back to the server with the form and not allow users to alter the value in the textbox.
Are you setting the Visible = false property at design time in the property sheet of the text box, or at run time in code ??
If you set the textbox Visible=false in code for e.g. in Form_Load, then it should work.
精彩评论