Textarea in gridview showing old values before saving and binding - c#

I have a GridView which consists of Textbox in each row and its textmode property is set to 'Multiline'.
Whenever I edit the Textbox and click Save button, the edited Textbox in gridview shows the old values for a second, gets saved in database and binds the new value.
The GridView is enclosed in an UpdatePanel and also its ViewState property is set to false.
Binding is done only after saving the records.
I don't know where it is going wrong.

I have a feeling it has something to do with when your databinding.
Try setting the viewstate back to true, then databind your gridview on
1) !Page.IsPostback
2) After you have finished the save operation

Related

how to stop validation control when a cell of gridview become clicked

i have a gridview and some text boxes with required field validator and buttons all inside of a table and table is inside of update panel.
I am displying data in textboxes on the click of a specific record of gridview and all was working fine but after applying some validation to text boxeses(e.g., required fied validator) as i click to the gridview validation get runs and the gridview record is not showing to me becuase of validation.
so how can i show data??
ongridview selected index change event
txtfirsName.Text= gvData.SelectedRow.cells[1].Text;
and i think above code not a problem but i have posted .real concern with validation

Can values from dropdownlists in detailsview be updated without autopostback?

I have a details view that is in "insert Mode" so the user just sees blank spaces to enter values. I have two drop down lists and I wanted to have the second ddl change its value by what was selected in the first ddl. I tried setting ddl1 to a label so ddl2 would change when the label changed. The problem I am having now is that I need autopostback to update the value of the label, but selecting "autopostback" on the ddl1 makes my code throw a data binding error.
I was wondering if there was any way I could get around using autopostback and still update values selected in the first ddl to the label.
Thank you.
Try using AjaxControlToolkit. It has a feature to cascade ddlists. Use updatepanel as container for both of ddls so you can omit autopostback.
Your query is not completely clear. But if you want to change the dd2 value on change event of dd1, you can use the following code:
$("#<%= statusDDL.ClientID %>").val($("#<%= dd1.ClientID %>option:selected").text() );
It is not clear whether you want value or text property.
Also I am not 100% that this syntax will work. But obviously it can be done using this concept searching on net for your requirement

asp.net gridview editing

I have a gridview (Edit and Delete enabled) that shows a table. A Text Box and A Button. When I type something in the textbox and click the button, the button runs the datasource.filterexpression and filters out the rows.
The question whenever I click on the edit button after the filter has been applied The grid auto resets back to the original table? How can I solve this?
After saving the edited record in the GridView RowUpdating event, re-apply the filter and call DataBind()

how to set focus the dropdown item in the page load event?

Based on my dataset row value , my drop drown will focus the particular list item in page load event.
ddparty.SelectedIndex = ddparty.Items.IndexOf(ddparty.Items.FindByValue(ds.Tables[2].Rows[0][1].ToString()));
i try the above code its not working.
Setting the property:
mydropdown.SelectedItem
or
mydropdown.SelectedValue
Make sure you do this AFTER databinding the dropdown control.
Don't know if you've set your DataValueField to the datatable's second column. On the other hand if you've set your DataTextField to it, try FindByText instead of FindByValue.
As a side note, try to quickwatch in the debugger, the value of the index you get.

How to retrieve a changed value of databound textbox within datagrid

ASP.NET 1.1 - I have a DataGrid on an ASPX page that is databound and displays a value within a textbox. The user is able to change this value, then click on a button where the code behind basically iterates through each DataGridItem in the grid, does a FindControl for the ID of the textbox then assigns the .Text value to a variable which is then used to update the database. The DataGrid is rebound with the new values.
The issue I'm having is that when assigning the .Text value to the variable, the value being retrieved is the original databound value and not the newly entered user value. Any ideas as to what may be causing this behaviour?
Code sample:
foreach(DataGridItem dgi in exGrid.Items)
{
TextBox Text1 = (TextBox)dgi.FindControl("TextID");
string exValue = Text1.Text; //This is retrieving the original bound value not the newly entered value
// do stuff with the new value
}
So the code sample is from your button click event?
Are you sure you are not rebinding your datasource on postback?
When are you attempting to retrieve the value from the TextBox? i.e. when is the code sample you provided being executed?
If you aren't already, you'll want to set up a handler method for the ItemCommand event of the DataGrid. You should be looking for the new TextBox value within that method. You should also make sure your DataGrid is not being re-databound on postback.
I would also highly recommend reading through Scott Mitchell's excellent article series on using the DataGrid control and all of it's functions:
https://web.archive.org/web/20210608183626/https://aspnet.4guysfromrolla.com/articles/040502-1.aspx

Categories

Resources