hi, is it possible to assign values to button? I will not need to enter any values and when i click on the button, the values on the datagrid and database will automatically change. Is there anyway to do it? Thanx in advance.
Assign values to button
Collapse
X
-
You can use the Tag property of any control to store anything. You can add the Tag object at design or run time:Originally posted by fanoftvbhi, is it possible to assign values to button? I will not need to enter any values and when i click on the button, the values on the datagrid and database will automatically change. Is there anyway to do it? Thanx in advance.
Note -- if you are writing in C#, you have to do casting. VB lets you be sloppy. HTHCode:Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click Dim b As Button = sender MsgBox("Hi from " & b.Tag) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Button1.Tag = 19.98 Button2.Tag = 42 End Sub -
Sorry, I was building a Window's App. To keep the Web controls lightweight, they do not have a Tag property, but it is easy to add one by extending the WebControls.But ton class. Here is an example for a TreeNode. The code for an extended Button class would be identical.Originally posted by fanoftvbThanx 4 the reply, I try it out and these errors occur
'Tag' is not a member of 'System.Web.UI. WebControls.But ton'.
Name 'Button1' is not declared.
pls help...thanxComment
-
Why would you assign values to a button? Are you trying to change the text dynamically? What have you tried thus far?Originally posted by fanoftvbhi, is it possible to assign values to button? I will not need to enter any values and when i click on the button, the values on the datagrid and database will automatically change. Is there anyway to do it? Thanx in advance.
AricComment
-
Originally posted by AricCWhy would you assign values to a button? Are you trying to change the text dynamically? What have you tried thus far?
Aric
Hi, i was thinking that if i click on the button the data in my database will change. I will not need to enter any information, the data will click automatically when i click on the button..is there a way to do it?Comment
-
You coud do something simple like put the number in the button name, Btn1, Btn10, Btn42, etc.Originally posted by fanoftvbHi, i was thinking that if i click on the button the data in my database will change. I will not need to enter any information, the data will click automatically when i click on the button..is there a way to do it?
Code:Private Sub Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn1.Click, Btn10.Click, Btn42.Click Dim b As Button = sender Dim s As String = Strings.Right(b.Name, Len(b.Name) - 3) Dim i As Integer = Integer.Parse(s) MsgBox("Hi from " & i) End SubComment
Comment