Setting the value of Label when a FormView is bound - asp.net

I have a ASP.NET page with a FormView control. When the FormView is bound I'd also like to set the Text property of a Label control that is outside the FormView.
What is the best way to do this? I thought about using the DataBinding or DataBound event of the FormView but the EventArgs parameter provided does not seem to give me access to the current values.

The FormView control has a DataItem property. Give the DataBound event another shot.

Related

Proper event to populate a ComboBox/DropDownList inside of a Telerik RadGrid

I am trying to figure out what the correct event would be to populate a ComboBox in a Telerik RadGrid or any ASP.NET grid from the CodeBehind. When the user clicks Edit on a row the ComboBox should be populated with its items.
The only examples I have seen are using the DataSourceID property in the aspx page. I prefer doing all of my populating manually in the code behind:
ComboBox1.DataSource = colorList;
Combobox1.DataBind();
You can access child controls in a grid column in:
ItemDataBound - fired for each item (so you need to check for GridDataItem types or GridEditItem, depending on your goal)
ItemCreated - similar, but you don't have the data item object associated with each item
ItemCommand - when Edit is clicked an Edit command is invoked so you can access it.

asp.net FormView display ItemTemplate without databind and datasource

I have a FormView that has a repeater inside. In order to render the ItemTemplate I do a fake datasource and databind.
Then I look for the Repeater with FindControl and do another DataSource and DataBind.
So in this case HardCodedData is just a placehoder to get me to renter the FormView ItemTemplate.
FormView1.DataSource = HardCodedData;
FormView1.DataBind();
Repeater r = ((Repeater)FormView1.FindControl("repeater1"));
r.DataSource = GetMyData();
r.DataBind();
Is there a better way? Can I just get FormView to renter without giving it fake data? Or can I pass the repeater data through the FormView DataSource?
As a repeater control is inside the form view than you should bind this repeater control inside the form view's event DataBound threw that you will be get exact data which you want to get. Put your following code inside your FormView1_DataBound event.
Repeater r = ((Repeater)FormView1.FindControl("repeater1"));
r.DataSource = GetMyData();
r.DataBind();
May be this solution can help you....

How do you handle events on controls created during the GridView.RowDataBound event?

So on the .NET GridView control there's a RowDataBound event, at which time I create a DropDownList for each row in a particular column.
When that DropDownList changes on the client, I can get it to post back, but the control's state is already gone. What's the best approach to handling events for controls created during the RowDataBound event?
I'm curious: why are you adding these DropDownLists to the GridView in the RowDataBound event? I genuinely can't think of a reason to do this.
Even if you have just a placeholder DropDownList in the original RowTemplate, you should be able to bind the control and assign appropriate event handlers.

Not able to fill a DropDownList according to the selection of another DropDownList

Respected sirs
I am using a DropDownList control and binding it to a LinqDataSource.
According to the selection of the mentioned DropDownList, I need to bind another DropDownList control.
I have handled the SelectedIndexChanged event for first DropDownList. When this SelectedIndexChanged occurs, page is getting refreshed. To prevent page from beend refreshed, I am using an UpdatePanel control. But, still the second DropDownList not loading.
Please give me a solution.
Thanks
Saravanaa
Place the second DropDownList inside the UpdatePanel.
You may want to consider using CascadeDropDown too.

How should I set an asp.net label's text to some value in another control?

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";

Resources