Hi,
I have a couple Grids on my page which include a "Download" GridButtonColumn that has AJAX disabled via Javascript to enable a File Download. When clicking these download buttons, the Code behind uses GetDataKeyValue to get the ID of the row:
However, this code works for all of my other functions (edit), but on the "Download" button it automatically pulls the TicketID from the first Row of the Grid. It doesn't matter if I delete rows or change pages on the Grid, the GetDataKeyValue method always pulls the first item's ID rather than the row I've clicked.
I have DataKeyNames="TicketID" set in the MasterTableView of the Grid, and the Grid is populated with a LINQ/IQueryable Datasource.
I've also attempted to create a work-around for this problem by using this code instead, considering I have a column which displays the TicketID:
But to no avail, it is still grabbing the first Row's "TicketID". When constructing the GridDataItem item object, it's almost as if it's automatically grabbing the wrong Row from the very beginning. I've included an image of what exactly is happening.
Here is also the block of ASPX code of my Grid.
Oh, and here's the JavaScript I'm using to Disable AJAX on the Download Button:
Any ideas are greatly appreciated, as I've hit a brick wall with this one... Or maybe I've just got tunnel vision from staring at this for so long.
Best Regards,
Landon
I have a couple Grids on my page which include a "Download" GridButtonColumn that has AJAX disabled via Javascript to enable a File Download. When clicking these download buttons, the Code behind uses GetDataKeyValue to get the ID of the row:
protected
void
CompleteTickets_ItemCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.CommandName ==
"Refresh"
)
{
CompleteTicketsGrid.Rebind();
}
if
(e.CommandName ==
"Download"
)
{
// Get Ticket ID
GridDataItem item = (GridDataItem)e.Item;
int
ticketID = Convert.ToInt32(item.GetDataKeyValue(
"TicketID"
));
// Use Ticket ID to Get File from File Repository
}
}
However, this code works for all of my other functions (edit), but on the "Download" button it automatically pulls the TicketID from the first Row of the Grid. It doesn't matter if I delete rows or change pages on the Grid, the GetDataKeyValue method always pulls the first item's ID rather than the row I've clicked.
I have DataKeyNames="TicketID" set in the MasterTableView of the Grid, and the Grid is populated with a LINQ/IQueryable Datasource.
I've also attempted to create a work-around for this problem by using this code instead, considering I have a column which displays the TicketID:
int
ticketID = Convert.ToInt32(item[
"TicketID"
].Text);
But to no avail, it is still grabbing the first Row's "TicketID". When constructing the GridDataItem item object, it's almost as if it's automatically grabbing the wrong Row from the very beginning. I've included an image of what exactly is happening.
Here is also the block of ASPX code of my Grid.
<telerik:RadGrid
runat=
"server"
ID=
"CompleteTicketsGrid"
Enabled=
"true"
Width=
"100%"
AutoGenerateColumns=
"false"
Skin=
"Default"
GroupingEnabled=
"false"
PageSize=
"10"
AllowPaging=
"true"
OnNeedDataSource=
"CompleteTickets_OnNeedDataSource"
OnItemCommand=
"CompleteTickets_ItemCommand"
>
<MasterTableView
DataKeyNames=
"TicketID"
CommandItemDisplay=
"Top"
CommandItemSettings-ShowRefreshButton=
"true"
CommandItemSettings-ShowAddNewRecordButton=
"false"
CommandItemStyle-HorizontalAlign=
"NotSet"
TableLayout=
"Fixed"
Name=
"Unpriced"
AllowPaging=
"true"
>
<Columns>
<telerik:GridBoundColumn UniqueName=
"TicketID"
DataField=
"TicketID"
HeaderStyle-Width=
"5%"
ItemStyle-Width=
"5%"
HeaderText=
"#"
></telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName=
"Customer"
DataField=
"Customer"
HeaderStyle-Width=
"15%"
ItemStyle-Width=
"15%"
HeaderText=
"Customer"
></telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName=
"Location"
DataField=
"Location"
HeaderStyle-Width=
"18%"
ItemStyle-Width=
"18%"
HeaderText=
"Location"
></telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName=
"JobNo"
DataField=
"JobNo"
HeaderStyle-Width=
"9%"
ItemStyle-Width=
"9%"
HeaderText=
"Job #"
></telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName=
"CreatedDate"
DataField=
"DateCreated"
HeaderStyle-Width=
"11%"
ItemStyle-Width=
"11%"
HeaderText=
"Date Created"
ReadOnly=
"true"
DataFormatString=
"{0:d/M/yyyy}"
></telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName=
"OrderedBy"
DataField=
"OrderedBy"
HeaderStyle-Width=
"11%"
ItemStyle-Width=
"11%"
HeaderText=
"Ordered By"
ReadOnly=
"true"
></telerik:GridBoundColumn>
<telerik:GridButtonColumn UniqueName=
"Download"
ButtonType=
"LinkButton"
Text=
"Download"
CommandName=
"Download"
ItemStyle-Width=
"12%"
HeaderStyle-Width=
"12%"
/>
<telerik:GridButtonColumn UniqueName=
"LoadTicket"
ButtonType=
"LinkButton"
Text=
"Load Ticket"
CommandName=
"LoadTicket"
ItemStyle-Width=
"13%"
HeaderStyle-Width=
"13%"
/>
</Columns>
</MasterTableView>
<ItemStyle Height=
"40"
VerticalAlign=
"Middle"
/>
<AlternatingItemStyle Height=
"40"
BackColor=
"CadetBlue"
ForeColor=
"White"
VerticalAlign=
"Middle"
/>
<ClientSettings>
<ClientEvents OnCommand=
"OnGridCommand"
/>
<Scrolling AllowScroll=
"False"
UseStaticHeaders=
"True"
/>
</ClientSettings>
</telerik:RadGrid>
Oh, and here's the JavaScript I'm using to Disable AJAX on the Download Button:
// Disables Ajax on Buttons Clicked in Grid
//
function
OnGridCommand(sender, args) {
var
itemArgument = args.get_commandArgument();
var
itemCommand = args.get_commandName();
if
(itemArgument ==
"DisableAjax"
|| itemCommand ==
"Download"
) {
window[
"disableAjax"
] =
true
;
}
else
{
window[
"disableAjax"
] =
false
;
}
args.set_cancel(
false
);
}
Any ideas are greatly appreciated, as I've hit a brick wall with this one... Or maybe I've just got tunnel vision from staring at this for so long.
Best Regards,
Landon