I want to set default value current time for AspxGridView TimeEdit control. Is it possible?
KR,
Çağın
This can be done by using the ASPxGridView's CellEditorInitialize event. Check the value of the e.Column.FieldName property and then set the e.Editor.Value as needed.
Related
I am extending the ButtonField DataControlField and I want to set its .Visible property inside this extension.
As it does not have OnPreRender method like other Asp.Net controls, Where is the best place to set .Visible property? Which method? CreateField?
Typically visibility can be set at anytime before the Render event.
Depending on what logic you're trying to implement I'd suggest looking at the ItemDataBound event for whichever data-bound you're working with.
Perhaps if you could be more specific about what you're trying to achieve and why you're setting the visbility I can help further.
Depending on the case, I'd like to hide a databound control in a page. But no matter what I try, it seems like the control will try biding no matter what. I've tried setting Visible="false", but it would still try to bind. I've tried putting the control into a placeholder and then hide the placeholder, it will try to bind anyway. I've also tried putting it into a MultiView, same thing. You would think that in a wizard interface using a MultiView you would not want the controls in the next steps of the wizard to bind, but no. It binds anyway...
The only way I've found is to unset and set the DataSourceID property which seems to prevent binding.
Is this really the only option?
Thank you.
I think that you are on a good path. Do not set the data source id. When it comes time to display the data (which I presume is triggered by a user click), explicitly databind your control.
when you set the datasourceid on your control, then the asp.net framework will automatically data bind when the page's OnDataBind event occurs.
Could it be that you're using a datasource control to bind to? The DataSourceID property being set indicates so. If you don't want it to bind to such a control you can opt to take out the DataSourceID property in markup and explicitely set it in codebehind only when you need it.
I'd like to set the text of two labels to values found in a FormView on a page (whose data comes from an SQLDataSource.)
What's the best way to do this? I'm thinking of using the DataBound event for the FormView to set the label text to the value of a field in the FormView, or of using the SQLDataSource Selected event to set the labels to values retrieved by the query. Could I use the Page_Load event in conjunction with the FormView?
The FormView only displays one of the two values, though the other value is retrieved by the SQLDataSource.
I'm unfamiliar with accessing the data structures behind these controls but figure the data is there so I might as well use it rather than run the same SQL query twice.
My question then is which event do I use, which control do I access the data from, and how do I access the data from that control?
I'd use the OnDataBound event and get the value from the underlying datasource using:
lblExample.Text = ((DataRowView)((FormView)sender).DataItem)["fieldName"].ToString();
Hope it helps.
// CeriQ
If you're just trying to set a label, just set the label at the Page_load event:
myLabel.Text = "someValue";
I am trying to synchronise the selectedvalue of a combobox when navigating through records. Setting the combobox.selectedvalue doesn't work. I have tried refreshing the combobox but that doesn't work either. The combobox is databound.
If your ComboBox is data-bound (i.e. you've properly set its DataSource property), then you also need to make sure its DisplayMember and ValueMember properties are set to the correct fields.
When adding an EditItemTemplate of some complexity (mulitple fields in one template), and then parsing the controls from the RowUpdating event, the controls that were manually entered by the user have no values. My guess is there is something going on with when the data is bound, but I've had instances where simply adding and attribute to a control in codebehind started the behavior and removing that code made the code work. As a work-around, I can Request(controlname.UniqueId) to get it's value, but that is rather a hack.
Edit
When I access the value like so
TextBox txtValue = gvwSettings.SelectedRow.FindControl("txtValue") as TextBox;
the text box is found, but the .Text is not the user input.
Did you turn off ViewState?
Did you add control programmatically in the template? If so, did you create them at the correct stage?
You should be able to use the GridViewUpdateEventArgs to retrieve the inputted value, for example:
TextBox txtValue = gvwSettings.SelectedRow.FindControl("txtValue") as TextBox;
I have used that syntax before and it works like a charm.
Moved post-back data-bind to Page_Init