In my project I'm showing a gridview in which I'hv included a buttonfield...I want to download a file, when user clicks the button inside gridview whose path is stored in database
and the file is stored in localfile system...
thanks in advance.
You can use the RowCommand Event of a gridview to responde to a button click and perform an action.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx
You can use the RowCommand event of the GridView control. Make sure your button has setup the CommandName and CommandArgument. The CommandName will distinguish between different events handled by the GridView RowCommand event. And the CommandArgument will contain any value you need to send to the GridView RowCommand through the Button click event.
Related
I am using C#, ASP.net 3.5
How to capture the row change event of repeater in javascript?
There is no such event exists in Repeater control. Take a look at MSDN article.
You should bind to the change event of items in your row in javascript. The default on_change event of .net does a postback, so you can handle it server side. You can also capture the mouse hover event on the row in javascript and handle the mouseenter en mouseleave methods to update your data or something. See: how to handle row change event of table using jquery?
I have a textbox in a gridview. The column template for the gridview binds data to the textbox. The original value will be called X. If I change the text in the textbox inside the grid view to Y the onTextChanged event will fire when I press a button. After I have changed the text to Y, and the event has fired, the event will continue to fire if each time i click the button. If I change the text to the orignal value, X, the onTextChanged event stops firing.
There are textboxes outside of the gridView. They all call onTextChanged as expected; When text is changed from what was there before.
How can I make the onTextChanged act like its expected instead of an onTextIsNotOrignalValue?
Have you tried to enable ViewState for the text box on the grid view? I am not sure if you have to enable Viewstate on the gridview itself.
Did you set AutoPostBack of Textbox to True?
I am using Telerik RadGrid, i add a new button in the grid but how can i write an event for this button (Buy) for example when the user press (Buy) it will add this item to his cart with its price in order to calculate his bill.
regards
You need to listen for the ItemCommand event:
<telerik:GridButtonColumn UniqueName="Buy" ButtonType="LinkButton"
Text="Buy" ConfirmText="Add to cart?"
OnItemCommand="rg_ItemCommand" CommandName="AddToBasket" />
In your codebehind
protected void rg_ItemCommand(object sender, GridCommandEventArgs e)
{
if(e.CommandName == "AddToBasket")
{
// Add to basket code here
}
}
You may also need to set the CommandArgument during the ItemCreated or ItemDatabound events, or get it using something like rg.MasterTableView.DataKeyValues[e.Item.Index]["ItemId"].ToString(); after setting ClientDataKeyNames="ItemId" in your MasterTableView settings part in the ascx file (if it is databound).
You need to use the ItemCommandEvent of grid. The ItemCommand event is raised when a button is clicked in the Telerik RadGrid control. This allows you to provide an event-handling method that performs a custom routine whenever this event occurs. Follow the LINK to have more details.
When you create the button you'll want to add an OnClick event to it to handle the click on the button. In this event you'll then add the item to the cart. You'll need to parse the parent row of the button to know which item it is.
Edit:
Since you are using a GridButtonColumn and not adding a button as you stated then this applies instead (from Telerik.com):
This column renderes a button of the
specified ButtonType in each
corresponding cell of the items of
type GridDataItem and
GridEditFormItem. You can use this
buttons to fire command events that
can be handeled in RadGrid.ItemCommand
event handler. This, in combination
with the event bubbling mechanism in
Telerik RadGrid, allows you to create
a column of custom button controls,
such as Add, Remove, Select or Edit
buttons.
So essentially you'll need to use the grids ItemCommand event to handle the button click.
I have a gridview where i have a radio button. What i need is to on the selection of the radiobutton i have to find the datakey of the gridview. Also one more issue with that is , i can select more than one radio button, which should not happen.
You need to use a literal control to inject radio button markup.
This will handle grouping so only one radio button is selected.
You cannot do it with the standard radio control group.
See this for a complete example with working code:
http://www.asp.net/data-access/tutorials/adding-a-gridview-column-of-radio-buttons-vb
I am having a DataGrid in one usercontrol which is getting filled with some data when I press some button(ouside it). This Datagrid is filled by one linkbutton also. When I click this LinkButton then OnItemCommand or SelectedIndexChanged should fire, but both the events are not firng. While the control's PageLoad event is firing.
Please let me know where I am doing the mistake.
Thanks
Is your control added dynamically, using something like Page.LoadControl()? If so, events won't fire unless the control is dynamically added for each request. That's the only way the control tree can be properly built again. I usually do this in Init().
https://web.archive.org/web/20211029043701/https://www.4guysfromrolla.com/articles/042402-1.aspx
For those that see this post, looking for an answer. Most likely, you're rebinding the data to the datagrid on every call. Use a conditional and check !this.IsPostBack.