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.
Related
I have a Telerik RadGrid which uses the EditFormSettings like this:
<EditFormSettings EditFormType="WebUserControl" UserControlName="~/UserControls/MyUserControl.ascx" >
<EditColumn ButtonType="ImageButton" />
</EditFormSettings>
Within MyUserControl.ascx, I have a button which I'd like to trigger an event handler when clicked. The two ways I know of doing this are as follows:
OnClick="btnOkay_Click" as a button attribute, where the event handler is in the code behind
CommandName="Update" as a button attribute, where this is handled by the event handler passed into the OnUpdateCommand attribute of the RadGrid
Both of these work. However my problem is that they stop working when the RadGrid is within a user control within a Repeater ASP.NET control. In this case, the button event handlers do not get fired (in either of the methods above).
I notice that when I bind my repeater:
rpt.DataSource = Data
rpt.DataBind()
If I wrap that in a if(!Page.IsPostBack), then the edit form doesn't appear at all when I click on the RadGrid row's edit link. So I had to remove that IsPostBack check. I don't think think this is the cause of my problem, as I've tried explicitly not doing this when clicking my update button (by breaking into the debugger). I just thought I'd mention it incase it was related.
Can anyone think of a reason why this would break in a Repeater?
Found the problem with a little help from a work colleague! Turned out to be because I was binding the Repeater in Page_Load rather than Page_Init. Changing it to Page_Init resolved the issue.
I have a code where I have a asp:Button control with CommandName attribute. GridView has OnRowCommand. When I click the button, I execute a method on RowCommand event to update records. Inside of this method I validate input. How can I add client-side validation to that button click event event, so I have validation in both places?
Any suggestons?
I am using a GridView in ASP.net with a pre-added buttons. The GridView's data source is from a list of BookingRowStatus
BookingRowStatus(Row, m_AStatus, m_BStatus, m_CStatus, m_DStatus, m_EStatus, m_FStatus)
The arguments that you can see are the Columns. I added RowCreated event to check m_XStatus to enable/disable the buttons depending on the text inside it ("X" = disable | "Y" = enable).
Next is I added a RowCommand event which should catch the event when a button in GridView is clicked. However, whenever I click the button, it invokes RowCreated instead of RowCommand. I added a break point on both of the said Events and I can see that it doesn't even pass RowCommand; it goes straight to RowCreated.
My question is how do I Invoke RowCommand when I press a button on the DataGrid?
The RowCreated event will fire before the RowCommand event is hit as the child controls (i.e. the rows) will be created on post back before you can access the values from them.
Set a breakpoint in both and see if they are both triggered.
Although your solution should work, an easier solution would be to bind the Button directly to the fields value. E.g.
<asp:Button runat="server" Enabled='<%# Eval("m_XStatus") = "Y" #>' />
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.
I want to call Textbox.OnTextChange event without having to click a submit button or any button. How can I do this? As I enter text in the textbox, I want the ontextchange event to fire.
I would elaborate this further.I've a function for validating my entry in textbox which I'm calling ontextchange property.Now this function should be called without me changing focus from my textbox.
You can use onkeypress , onkeyup and onkeydown events for this.
http://www.w3schools.com/tags/tag_input.asp
Example :
<asp:TextBox ID="TextBox1" runat="server" onKeyPress="javascript:alert('Key Pressed');"></asp:TextBox>
you can set AutoPostBack to true on the textbox control. when the client side change event fires (when the focus changes from the textbox to something else), the page will do a postback automatically.
If you want a postback:
You want to use the onkeypress or onkeyup javascript event to run the __doPostBack javascript method. __doPostPack has some parameters you will need to look up on msdn
Otherwise just use the onkeypress or onkeyup javascript event to do whatever else it is you need with javascript.