Search code examples
asp.netaspxgridview

AspxGridView: How to Get Value of Keyfield or Spesific Column on the Click Event of DataItem Template Button?


I have an AspxGridView and a button inside of a DataItem Template of one column. I use Button_Click event for this button and I need to get values of current row in this event when I click on this button. AspxGridView's events' have "e.Keys[]" or "e.KeyValue" etc properties but I couldn't find anything for the button EventArgs. How can I get the values of columns or KeyValue? Thanks in advance.


Solution

  • You can also use the Container.keyvalue approach like this:

    <dxwgv:GridViewDataTextColumn VisibleIndex="3" Caption="Simple Hyperlink Column">
        <DataItemTemplate>
            <a id="clickElement" target="_blank" href="Default2.aspx?id=<%# Container.KeyValue%>"><%# "Show New Form, Key Field = " + Eval("CategoryID").ToString()%></a>
        </DataItemTemplate>
    </dxwgv:GridViewDataTextColumn>
    

    Sample online here: http://www.devexpress.com/Support/Center/e/E993.aspx