Gridview data display on demand of user - asp.net

I have connected GridView with a datasource. It works fine but it is displayed just at form load. I want to show it when user clicks the button. How to make it so?
Thanks

Try setting the Visible attribute of the GridView to false. In the Click handler of the button, set the Visible attribute of the GridView to true. Rebind and use an update panel if necessary.
If you post some source code, we can give you a working example.

Related

Can't change ImageButton tooltip or style on GridView fired postback event

Hi I'm having a really strange issue here. I have an ImageButton and Gridview, both of which I create on runtime. The Image button is a seperate control on the webform and is not linked in anyway to the Gridview. What I am trying to achieve is when the user completes the editing of a line in the GridView and clicks on the update row button, I perform a set of calculations on the input entered. If an error is found with the data entered, I then make visible the ImageButton which when clicked displays the error message. The function I am using to make visible or hide the Image button through
picCross.Style.Value = "display: none;"
and
picCross.Style.Value = "display: block;"
gets called on the Page.PreRender function. What I have discovered is that I am able to make changes to the ImageButton (changing the button's tooltip, setting its Style's value ) during a postback not fired by the GridView, such as when the user clicks on a button else where on the web form. If however I try making changes to the Imagebutton during the post back event of the GridView, such as when the user clicks on the edit row or update row button/link. The changes are not saved. What is even more strange is I do not have such an issue with labels. I can change the text of labels regardless on whether the change was made during the postback fired off by the Gridview control.
I have tried setting the ImageButton's EnableViewState to true and false but neither makes a difference. I have tried the same approach with panels and the same thing occurs, I can't change its properties during a postback caused by the gridview. My GridView has EnableViewState = True
P.S I'm binding the GridView on runtime too. Only my GridView's RowUpdating event fires. The RowUpdated event does not fire. I was hoping to try changing the ImageButton on RowUpdated, not that I think it would have made much of a difference anyway.
You should create the dynamic controls (Gridview and ImageButtons) in the PreInit event. Init event if you have a Master Page.

How can I update using Ajax when I am displaying an image in a handler?

I have a complex page. Basically, it is a ListView with images displayed through handlers. Paging is done through a datapager. This is all wrapped in an Ajax UpdatePanel so it pages seamlessly.
When the user sees a image they like and click on it, it should display in an image above the ListView. This work when I DON'T use the updatePanel, but of course, then I get flicker. Wrapping it in an update panel results in the paging working. When the user clicks an image it goes to the db as expected, but it simply never updates the image being displayed.
Here is how the image that is clicked on is defined.
<asp:ImageButton ID="imgbtnImage" runat="server" ImageUrl='<%#"~\Handlers\ThumbnailDBHandler.ashx?id=" & Eval("ID")%>' CommandArgument='<%#Eval("ID")%>'/>
does yout asp:ImageButton stays "in" update panel? 1 more thing, set update panel to use child as trigger. Because the event that postback in binable control is sometime not the control itself. It use the bindable control to postback.
eg. i have button in each grid view rows. when the button clicked, the update panel doesn't read the click event. it read the event as GridViewRowCommand. Not button click.
so set update panel to use child as trigger ans set to always update should solve the problem

How to disable listbox's click event

I have a listbox which acts as a list of items. If you click on some item, it's contents are shown in the panel on the right (few textboxes etc.).
I need to have a validation on these controls as all of them are required fields. And I do have it. The problem is that, even when the validators are not valid, user can click the listbox and change active index (that doesn't have impact on the panel on the right, as SelectedIndexChanged isn't fired).
The validators are standard RequiredFieldValidator with their Display property set to "Dynamic". So, what I want is to disallow the user clicking on the listbox and changing the index untill all validators are Valid.
What would be your solution for that? Is that even possible?
Did you try setting ListBox.Enabled = false when you actually do fire off the SelectedIndexChanged, and reenabling when your required fields meet the Page.IsValid requirement to proceed in code execution?

vs2008 web express: detailsview can not hide new button

On details view, I would like to hide the new button.
On page load I have successfully done so by the following code:
dtvwMyProfile.Rows[5].Cells[0].Controls[2].Visible = false;
But how do I hide the New button when I hit cancel or update button after I am done editing.
The New button keeps showing up. How do I hide it completely from the screen.
In some event, the visible property keeps changing to true and how do i find out that event?
I want to be able to do it at run time instead of design time.
Dynamically changing the properties of child controls created by the DetailsView is not recommended.
If the button is being created by the DetailsView itself then all you need to do is set AutoGenerateInsertButton to false and you can do that in Page_Load.
I do not recommend randomly selecting a page event and handling it. If you do that then chances are it will just break again when you change something else.
Maybe try to do that in the ModeChanged event handler, which fires after the mode changes... But can you ensure new is always at position 2? You may want to verify the button by its text or command name.

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