Gridview with linqdatasource refreshing view? - asp.net

I've a gridview bound to linqdatasource1 and a details bound to linqdatasource2 (for searching).
When I update the data on detailsview, my gridview is not updating. I've tried handling various gridview events and databinding the gridview in code but it doesn't seem to work.

Perform a .DataBind on the gridview as you manipulate data in the detailview

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.

Gridview related problem in asp.net

How can I enter data from textbox to gridview on the buttonclick event
A gridview is more commonly used for databinding to a source of table-like data. If you're just moving text from textboxes to grid/table, you might be better off using a regular table with empty asp labels in the cells. On postback, you can:
lblCell11.Text = txtBox1.Text;

How can I access the parent datasource in data expression syntax in Asp.net?

I have a Repeater inside the TemplateField for a GridView. GridView is bound to datasource1 and the repeater to datasource2. How can i access datasource1 from the ItemTemplate of repeater in data binding syntax (<%# %>) of repeater itemtemplate?
See this question. That question was relevant to Repeaters but you get the idea. The GridView exposes the RowDataBound event which you can handle in the same way.
Of course, I don't believe there is a way to access it via the declarative Databinding syntax.

Resources