reset ddl in gridview - asp.net

ive got a ddl in a gridview with two values: 0 = no and 1 = yes. I've also got an event on the dll SelectedIndexChanged so when the user selects 1 then it shows a panel with a form in it. the form has two buttons: submit and cancel.
what i'd like to do is when the user selects cancel reset the ddl in the gridview back to 0.
I have an event on the cancel button and can hide the panel with the form but I'm not sure how to find the ddl that triggered the event to show the panel. do i need to use the row datakey such as the id?

When your SelectedIndexChanged event occurs, note down the row index - in which the DropDownList is present - for example saving the row index in a hidden field. Then when the cancel Button is clicked, use that hidden field, extract the row index, find the DropDownList in GridView in that row and reset it.
Hint: Use Control.Parent to find the host of a control, for example CType(mydropdown1.Parent, GridViewRow).RowIndex
However doing all this through JavaScript would be much better, in this way your user would NOT experience the server round trips on each click, but obviously requires good grip on JavaScript.

Related

Can I fire button click event without firing pageload event?

I have a button on my page and and few textboxes which alters their context on page_load event. when I open the page for the first time it loads random data from a database to textboxes with a function in pageload and also I create those textboxes dynamically. what I want is to make some changes on textboxes texts and click the button than send new context of textboxes to database. But when I click on button, PageLoad event fires again and It regenerates the textboxes and the context of them alter naturally since they are newly created textboxes. I tried to use "if(!Page.isPostBack)" in pageload but then the textboxes and related objects are not being created and they become null.
how can I overcome this problem?
best thing I can think of is to find some way to fire buttons click event without firing PageLoad event, but I dont know how can I do it.
any help would be appreciated;)
From Comments
Can you regenerate the Textbox on each Page load Execution? and data assignment to these Textbox should be under !Page.IsPostback. All you have to do is to keep the IDs of the Textbox in ViewState only first time page load and next regeneration of Textbox will have the previous stored ID and you also have to store the ID corresponding data in ViewState. Makes sense?

About DropDownList

Am using DropDownList controls in ASP.NET binding values from SQL table. Some control have only one value, some control have more than one value. The SelectedIndexChanged event is not fired which control have only one value.
I set AutoPostBack=true and 0th item as select. Even though that event is not fired for that control?
SelectedIndxChanged event fires only if you change your selection and your DDL has AUTOPOSTBACK true.
If you have only one value in DDL then you don't need this event , you can write your desire code after you bind the dropdown on server side itself.
If you are not binding DDL from server side you can write your code on or after Page_Load event there you'll get the selected index
SelectedIndexChanged only fires when the selection has changed. If there's only one item in the dropdown list, you can never get this to fire (there's nothing to change to).
That being said, you can add a blank item to the top of the list (index 0), with the following at the top of the code where you populate the dropdown list:
MyDDList.Items.Add("");
That way you CAN choose something even with your one item.

The ListView LayoutCreated Event Is Not Fired After Handling ItemCommand

I am trying to update controls in the of a ListView control after handling the ItemCommand event.
My ListView displays line items of a purchase order in the as html table rows along with a TextBox to enter a new quantity and a Button to update the quantity. My ListView then displays sub-totals, discounts, and a grand total of the line items above in the as html table rows as well. On initial load, I set the values of the controls in the ListView's in the LayoutCreated event handler.
When a new quantity is entered and the button to update is clicked, I handled the event in the ItemCommand event handler. I update the quantity of the specific line item. I then re-bind my ListView to the underlying collection and call DataBind(). The problem is, LayoutCreated is not fired this time around, only on initial load.
My work around is to just pull those controls out of the and address them as static controls, but I like having them inside because my table markup can be fully contained in the and my can show cleanly without having to juggle the static controls' display properties.
Is what I am asking possible? Thank you for any help you can provide.
I'd reccomend handling the DataBound event of the ListView (instead of the LayoutCreated event), and setting the values there. That will get called everytime you re-bind the ListView, as well as when it loads for the first time, which (from your description) is what you want to do.

how to retrieve a value in datalist on the button click in DataList

We have a Datalist in which we have some data, with every Item we have a button control. What I want to achieve is that on the button click, the data related to that particular row of Datalist is fetched whose Button control is clicked. How to accomplish this? The problem is how to attach the button control with values related in that particular row? Note that I am using ArrayList as the Datasource since I am enabling padding via pageDataSource class...
Implement the OnDataBinding event for the Button. Then in the Button set the CommandArgument to something that will identify the row you are clicking. Then implement the OnItemCommand event for the DataList. You will be able to read the CommandArgument for the Button that was clicked and then perform whatever action you need.

DropDownList Setting Default Value

How should I get a value displayed in the DropDownList when redirected through a cancel buttton. The value in the page where cancel button is there in a TextBox should be caught in the DropDownList.
This DropDownList has SelectedIndexChanged event also fired for which on selection of a country in the list we get a ListView displayed in the same page. In that ListView we have an add button which will redirect us to another page called addcountry in which we have few controls. In those controls one TextBox I am getting value through QueryString in an enabled False state. Now again I need that value displayed in the DropDownList when I click cancel button.
How can I solve this problem?
Using $_POST and $_GET Variables you should be able to retreive almost any value from a form and put it in the right place on a new page, this right place can be one of your drop down list element...
To make absolutly sure your Cancel Button will send the good value to the right page put it in an independant form that has your new page (where you have yout dropdown list) as its action, and in this seperate form put an hidden field that holds the specific value you wanna see in this dd list ...
Hope I am clear but starting with your very "fuzzy" and blur question It is hard to help you.

Resources