dropdownlist is always null in oneditcommand in datalist - asp.net

I'm new to asp.net trying to use datalist control.
on edititemtemplate section i have put up a dropdownlist control. It has values in it. What I want is to select a value in edit mode but when I go to event (as set in oneditcommand ) my codes cannot find dropdownlist though its in edititemtemplate. Please check my codes below
DropDownList ddl = e.Item.FindControl("ddlType") as DropDownList;
ddl.Items.FindByValue((e.Item.FindControl("lblType") as Label).Text).Selected = true;
What I'm doing wrong?
thanks
-Navi

take a look at this link. Typically, you access controls like this at runtime by handling either the DataList's ItemCreated or ItemDataBound event.

Related

Pass selected gridview value to detailsview template field in edit Mode

DetailsView1 shows master detail from selected record of GridView1.
In edit mode, I have included a functionality for search, where on user click, GridView2 visibility is enabled.
I would like to have data from a selected row value (eg "accountnumber") from GridView2 loaded into a textbox control in DetailsView1 when I want to update "accountnumber".
How can I achieve this using VB.NET?
I put together a few ideas to come up with this, which worked perfectly well.
Dim TextBox As TextBox = TryCast(DetailsView1.FindControl("TextBox1"), TextBox)
TextBox.Text = GridView2.SelectedRow.Cells(0).Text

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.

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.

gridview sorting

I have a gridview that I load from a linq query.
MyGridData is a the list that's returned from the linq query and that contains a variable called MyVariable. So, in the code behind I have:
MyGrid.DataSource = MyGridData;
MyGrid.DataBind();
I then went to the aspx source and added AllowSorting = true and to the boundfield I want to enable sorting for, I added SortExpression = "MyVariable".
When the page renders, if I click on the header of the column to sort the grid, I get a yellow death screen with this message:
The GridView 'MyGrid' fired event Sorting which wasn't handled
What am I doing wrong?
Thanks.
You have to implement the handler for the Sorting-Event in the Codebehind. Sort your datasource and bind your grid again.

ASP.NET GridView e.NewValues == e.OldValues

Why would a GridView control's RowUpdating/RowUpdated event arguments have NewValues == OldValues regardless of user input?
I've found the answer to this now after some poking and rearranging.
Seemingly it was a DataBind in page load that was resetting the new values to the old ones before the event handler. Should have guessed.... :)

Resources