or
<telerik:RadGrid ID="MyGrid" OnItemCommand="MyGrid_ItemCommand" Skin="Sitefinity" AllowSorting="True" AutoGenerateColumns="false" AllowPaging="True" PageSize="10" runat="server" GridLines="None" Width="100%"> <PagerStyle EnableSEOPaging="true" SEOPagingQueryStringKey="p" Mode="NumericPages"> </PagerStyle> <MasterTableView> <Columns> <telerik:GridTemplateColumn HeaderStyle-Font-Bold="true"> <ItemTemplate> <%#Eval("Name")%></ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn HeaderStyle-Font-Bold="true" HeaderText="Progress"> <ItemTemplate> <div class="progress progress-success progress-striped" style="position: relative; top: 10px;"> <asp:Panel runat="server" ID="progressBar" EnableViewState="false" CssClass="bar progress"> <%#Eval("Complete")%> / <%#Eval("TotalCount")%> </asp:Panel> </div> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn HeaderStyle-Font-Bold="true" HeaderText="Manage" ItemStyle-Width="220px"> <ItemTemplate> <div class="btn-group"> <asp:HyperLink ID="matchLink" CssClass="btn" runat="server" Style="color: #333 !important;" Text="<i class='icon-check'></i> Match" /> <button class="btn dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span> </button> <ul class="dropdown-menu"> <li><a href="#message" data-toggle="modal"><i class='icon-envelope-alt'></i>Send Message</a></li> <li> <asp:LinkButton ID="downloadLinks" runat="server" Text="<i class='icon-download-alt'></i> Download Data" /></li> </ul> </div> <!-- Modal --> <div id="message" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> ×</button> <h3 id="myModalLabel"> Send Message</h3> </div> <div class="modal-body"> <asp:TextBox TextMode="MultiLine" ID="messageTextBox" Width="500px" placeholder="Type your message here…" runat="server" Rows="10"></asp:TextBox> </div> <div class="modal-footer"> <button class="btn" data-dismiss="modal" aria-hidden="true"> Cancel</button> <asp:Button ID="sendMessageButton" CommandName="SendMessage" CommandArgument='<%#Eval("Id")%>' CssClass="btn btn-primary" Text="Send" runat="server" /> </div> </div> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView> </telerik:RadGrid>protected void MyGrid_ItemCommand(object sender, GridCommandEventArgs e) { // code }
CommandArgument
?by the user?
Here is the RadGrid_ItemCommand event:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) { Trace.Write("RadGrid1_ItemCommand: starting up..."); if (e.CommandName == "ChangeStatus") { GridDataItem item = (GridDataItem)e.Item; //Get the record IDs from the DataKeyNames System.Data.DataRowView oRow = (System.Data.DataRowView)item.DataItem; int iApp_id = Convert.ToInt32(item.GetDataKeyValue("app_id")); int iCli_id = Convert.ToInt32(item.GetDataKeyValue("cli_id")); bool bIsFav = Convert.ToBoolean(item.GetDataKeyValue("IsFav")); Trace.Write("RadGrid1_ItemCommand: iApp_id: " + iApp_id); Trace.Write("RadGrid1_ItemCommand: cli_id: " + iCli_id); Trace.Write("RadGrid1_ItemCommand: bIsFav: " + bIsFav); int itmp = Convert.ToInt32(e.CommandArgument); //Toggle the Favorite status for that combination SqlConnection oConn = new SqlConnection(SqlDataSource_GridViewSolutions.ConnectionString); SqlCommand oCmd = new SqlCommand("toggle_gru_IsFav_Status", oConn); oCmd.CommandType = System.Data.CommandType.StoredProcedure; //ToDo make User name dynamic: oCmd.Parameters.Add(this.Page.User.Identity.Name); oCmd.Parameters.Add(new SqlParameter("strLoginID", "the_user")); oCmd.Parameters.Add(new SqlParameter("app_id", iApp_id)); oCmd.Parameters.Add(new SqlParameter("cli_id", iCli_id)); try { oConn.Open(); oCmd.ExecuteNonQuery(); } catch (Exception ex1) { Response.Write("Error updating favorite status: " + ex1.Message); } finally { oConn.Close(); oConn.Dispose(); } RadGrid1.Rebind(); }
Here is the markup for the RadGrid control:
<div class="apps_by_clients"> <asp:SqlDataSource ID="SqlDataSource_GridViewSolutions" ConnectionString="Data Source=BTSLSQLDEV01;Initial Catalog=GenericStorage;User ID=userid;pwd=xxxxxxxxx" SelectCommand="EXEC GetAppsWithFavStatus 'the_user'" runat="server" /> </div> <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" CellSpacing="0" DataSourceID="SqlDataSource_GridViewSolutions" GridLines="None" PageSize="30" Skin="Vista" Width="720px" AutoGenerateColumns="False" AllowFilteringByColumn="True" GroupingSettings-CaseSensitive="false" onitemcommand="RadGrid1_ItemCommand" OnPreRender="RadGrid1_PreRender"> <MasterTableView DataSourceID="SqlDataSource_GridViewSolutions" GroupsDefaultExpanded="false" DataKeyNames="app_id, cli_id, IsFav" > <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings> <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn> <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn> <Columns> <telerik:GridBoundColumn DataField="cli_name" FilterControlAltText="Filter cli_name column" HeaderText="cli_name" UniqueName="cli_name" SortExpression="cli_name"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="app_name" FilterControlAltText="Filter app_name column" HeaderText="app_name" SortExpression="app_name" UniqueName="app_name"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="app_id" DataType="System.Decimal" FilterControlAltText="Filter app_id column" HeaderText="app_id" ReadOnly="True" SortExpression="app_id" UniqueName="app_id"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn DataField="IsFav" HeaderText="Favourite?" UniqueName="IsFav" AllowFiltering="false" > <ItemTemplate> <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='./' CommandName="ChangeStatus" CommandArgument='<%# Eval("cli_id") %>' /> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> <EditFormSettings> <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn> </EditFormSettings> <PagerStyle PageButtonCount="5" /> </MasterTableView> <PagerStyle PageButtonCount="5" /> <FilterMenu EnableImageSprites="False"></FilterMenu> </telerik:RadGrid>
We are using ASP.Net 4.0 on Windows server 2008
We are using 2012.2.607.40 of the Telerik Radcontrols
Cheers,
Geoff