Hi,
I'm trying to port some of my plain ASP.NET Grid view code over to Webgrid. I went through the documentation and the forum here, I can't seem to find an answer on how to accomplish the following two tasks that I'm already doing it Gridview.
#1 Below gridview definition shows a image button on gridview, when the user clicks on it, the gridview _SelectedIndexChanged is fired, I can look up the gridview.SelectedDataKey[0] and popup a panel for the user. I know you have an Edit template, but my popup window is lot more involved than fit into a Edit template. I was looking at the Unboundfield to show this edit image, but how do I let the user click on it and which event gets me the selectedrows's datakey (I'm setting the Datakeyfield already)
<
asp:CommandField ButtonType="Image" HeaderStyle-Width="30px" SelectImageUrl="img/edit.png" ShowSelectButton="True">
<ItemStyle HorizontalAlign="center" />
</asp:CommandField>
#2 Instead of the CommandField above, I have the Buttonfield that fires a command which I capture in gridview_RowCommand event and check it as
if
(e.CommandName == "myCommand")....
do something.
asp:ButtonField ButtonType="Image" CommandName="myCommand" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Width="6%" HeaderText="CommandTest" ImageUrl="img/X-icon.png" ItemStyle-HorizontalAlign="Center">
How do I accomplish both these tasks in Webgrid?
Thanks
Hi mohanrs,
Thank you for posting in the community.
From the information you have given (using UnboundFields) I assume that you are using the WebDataGrid control. Attached is a sample for your consideration illustrating possible approaches to achieve your requirements.
A possible implementation for your first issue would be to show a WebDialogWindow containing your row specific information upon the click of a button inside a templated column. Note that in this scenario you can also use the grid's ItemCommand event to handle the button's command. The sample presents an example of how the container grid row may be accessed from the handler of a templated control:
An alternative implementation using UnboundFields is also possible, using WebDataGrid's selection behavior. This approach counts on initiating a postback on a change in the cell selection (given that the newly selected cell is in the unbound column) and handling the CellSelectionChanged event server-side, in order to once more display a WebDialogWindow.
Please let me know if this helps.
Hi Petar,
Thank you for the quick response. I tried your approach, but can't figure out how to setup the Button event to fire on the server side. Also, can't figure out how to setup the CellSelectionChanged event on the server side, the IDE only created the event on the client side. I'm attaching the sample that I played with, feel free to change the data source for your test.
All I'm trying to do in this sample is that, the first col and last col to be a button/image button and it fire a server side event when clicked and I can get the Datakey associated with that row on the server side.
I'm able to get the first column in the webdatagrid to show an image I want, but I want this to show image button control instead which is clickable and shows the hand icon on mouse over as you'd expect on a image button. I'd prefer to do this without the row selection enabled.
I had the grid ItemCommand wired up, but it never fires, obviously because I don't have any Commands hoooked up. Can you give me an example of how do I do this with different Commands that I can identify which column/row is clicked and pick up the datakey associated on server side with this same sample
I tried to search for answer myself, but your documentation is either non-existent or awful. Many times I searched for answers in the docs, I could never find it. I mean any dummy could figure out SetPropertyName() is meant for setting that property name. What I'm looking for is singificance of setting that property and related info described in detail in the doc. Usually all the doc shows is a one liner and no details at all, I know your guys probably picked up the idea from Microsoft on putting up useless documentation. And the object model for all the IG controls is strange to put it mildly. I worked with Component One and Telerik controls before, they all follow base ASP.NET object model for all the controls and then they branch off to specialized functionality which makes life lot easier when we port code from existing ASP.NET code base. IG object model on the other hand is convoluted, sometimes illogical and forces us to do things on multiple places such as aspx, javascript and code behind to get a single task accomplished. That makes it very hard for maintenance or update of the code in the future. Anyway, that's just some of the feedbacks that I hope you can relay to your product team.
I do see some cool features in your product and fairly quick responses for questions posed to your support or in the web forum, that makes up a bit for the trouble :-).
Looking forward to hear from you again.
Thanks,
Mohan