asp.net gridview - asp.net

How do I determine which SELECT button was clicked in a GridView?
The multiple SELECT buttons will be used for an application approval process.

If you are using Grid's Builtin Command buttons that you can easily recognize them using command name property of GridView_ItemCommand event of the grid.

You can listen to the RowCommand event from the GridView and handle the click from a button. On the button, you can set CommandArgument if you need to pass any data from the grid to the handler.

Related

dynamic radiobutton and checkbox columns register events

I have a gridview inside a User Control which is being filled with data from a data source dynamically. One of the things I need to support is switching a non-data-bounded column from checkbox column to radiobutton column dybamically.
everything's cool when I create the columns for display, but when I try to add an event to the CheckChanged (or Click) of the columns, the events doesn't fire - Not at AsyncPostBack and not at full postback. Moreover, the AutoPostBack is set to true and the checkboxes and radiobuttons do fire the postback, but not their events.
I don't think it's relevant, but the loaded usercontrol is in a ModalPopUpExtender from AjaxToolkit and it is being showed at server side (using a dummy button, and a clickable button ith a server side event on click). Also, all the ModalPopUpExtender controls are inside of an UpdatePanel, and only the clickable button is not.
thanks in advance.
I'm not sure if it'll work using Ajax and ModalPopUpExtender but I think you need to handle it in the OnRowCommand event of grid.
So, the column of the checkboxes should have been added in a static sort of way (declare the column and the checkboxes/radiobuttons in html) - the page would register to the events, or needed to be registered in PreRender of the GridView, after acknowledging that they were added during an Ajax postback... the latter is the best way... but for those who have no time to debug, first way is better. see also:
http://www.codeproject.com/KB/custom-controls/asp-ajax-custom-controls.aspx

trigger rowcommand event from commandfrield Edit button

I have a query regarding GridView Control : I added a commandfield inside my Gridview and set ShowEditButton="True" (By default it trigger RowEditing Event). Can i Trigger RowCommand Event Instead of RowEditing Event.
I know i can do it via other way but just got curious whether we can do this way
No you would need to use a control like ButtonField or LinkButton in order to trigger a custom command.

How to automatically click "update" button in asp.net control?

I used asp.net server side control to display and modify data in database, the control is just like this one:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/alleditablecolumns/defaultcs.aspx
what I want to do is after I click the "edit" button it will display a "edit" ui, and I want everytime I modify the data in the text box, asp.net will automatically click the "update" button for me to update the data i entered.
I tried to call the event handler, but failed.
There is a update command in asp.net, and how to programmatically call it ?
Try this. You can get the event refernce via this code
string postbackEvent = this.ClientScript.GetPostBackEventReference(this.button,"");
the postbackEvent will contains a __doPostback() function, which will invoke the button click in the server side. Assign this to some event, like onBlur of textbox.
this.txtSample.Attributes.Add("onBlur",postbackEvent);
Probably you will have to use the onTextChanged event of your TextBox control.
Set the autopostback attribute to "true"
<asp:TextBox AutoPostBack="True" ID="somethingID" OnTextChanged="CallSomeMethod" />
Look here : http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.autopostback.aspx

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.

DetailsView web control does not change to insert mode when insert is clicked

I'm binding a hashtable to a detailsview web control in ASP.NET 2.0. I have my edit/delete/insert link buttons on the detailsview, but when clicking new, the mode does not change.
Any ideas why?
I'm assuming that you have created a 'New' Button within the DetailsView. You should be able to simply handle the click event in your CodeBehind, and call the DetailsView.ChangeMode Method.
DetailsViewName.ChangeMode(DetailsViewMode.Insert)
DetailsViewName.DataBind()
In this case, I simply rebinded the DetailsView to show a blank form. You can also use the Click event to bind controls within the DetailsView form as well.
Fill out the form, click Add, and the Item_Inserting Event should get handled.

Resources