or

| <asp:Panel id="pnlContent" runat="server"> |
| <telerik:RadGrid id="grdProspects" runat="server" AutoGenerateColumns="false" AllowSorting="true" AllowPaging="true" PageSize="20" ShowHeader="true" ShowFooter="false" Width="760" GroupingEnabled="false" > |
| <ClientSettings EnablePostBackOnRowClick="true" EnableRowHoverStyle="true" AllowColumnsReorder="true"> |
| <ClientEvents OnRowContextMenu="Prospects_RowContextMenu" OnColumnContextMenu="Prospects_ColumnContextMenu" /> |
| <Selecting AllowRowSelect="true" /> |
| <Resizing AllowColumnResize="true" ResizeGridOnColumnResize="true" /> |
| <Scrolling AllowScroll="true" ScrollHeight="500" UseStaticHeaders="true"/> |
| </ClientSettings> |
| <PagerStyle Mode="NextPrevNumericAndAdvanced" Position="Bottom" /> |
| <MasterTableView TableLayout="Fixed" AllowMultiColumnSorting="true" NoMasterRecordsText="No Prospects" DataKeyNames="BACID" Width="760"> |
| <CommandItemSettings ShowExportToCsvButton="true" /> |
| <Columns> |
| <telerik:GridTemplateColumn ItemStyle-Width="60px" HeaderStyle-Width="60px" Reorderable="false"> |
| <HeaderTemplate> |
| <asp:HyperLink ID="lnkLegend" runat="server" NavigateUrl="" Text="Legend"></asp:HyperLink> |
| </HeaderTemplate> |
| <ItemTemplate> |
| <asp:Image ID="imgCalled" runat="server" ImageUrl="~/DesktopModules/BAOffice/images/called_on.gif" AlternateText="Called"></asp:Image> |
| <asp:Image ID="imgRegistered" runat="server" ImageUrl="~/DesktopModules/BAOffice/images/register_on.gif" AlternateText="Registered"></asp:Image> |
| <asp:Image ID="imgConfirmed" runat="server" ImageUrl="~/DesktopModules/BAOffice/images/confirm_on.gif" AlternateText="Confirmed"></asp:Image> |
| <asp:Image ID="imgFinalized" runat="server" ImageUrl="~/DesktopModules/BAOffice/images/final_on.gif" AlternateText="Finalized"></asp:Image> |
| <asp:Image ID="imgHasComment" runat="server" ImageUrl="~/DesktopModules/BAOffice/images/feedback.gif" ></asp:Image> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridBoundColumn HeaderText="Name" DataField="Name" SortExpression="SortName"></telerik:GridBoundColumn> |
| </Columns> |
| </MasterTableView> |
| </telerik:RadGrid> |
| </asp:panel> |
| <telerik:RadToolTipManager runat="server" ID="rttmRecruiterComments" Position="Center" Text="Loading..." |
| RelativeTo="Element" Width="350px" Height="300px" Animation="Fade" HideEvent="LeaveToolTip" ToolTipControl="controls/RecruiterComments.ascx"> |
| </telerik:RadToolTipManager> |
| <telerik:RadToolTipManager runat="server" ID="rttmLegend" Position="Center" Text="Loading..." |
| RelativeTo="Element" Width="250px" Height="200px" Animation="Fade" HideEvent="LeaveToolTip" ToolTipControl="controls/RecruiterLegend.ascx"> |
| </telerik:RadToolTipManager> |
| <telerik:RadAjaxManager ID="AjaxManager" runat="server" EnableAJAX="true" DefaultLoadingPanelID="LoadingPanel6"> |
| <ClientEvents/> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="pnlContent"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="pnlContent" /> |
| <telerik:AjaxUpdatedControl ControlID="AjaxManager" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| <telerik:AjaxSetting AjaxControlID="AjaxManager"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="pnlContent" /> |
| <telerik:AjaxUpdatedControl ControlID="AjaxManager" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| </telerik:RadAjaxManager> |
| Private Sub grdProspects_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles grdProspects.ItemDataBound |
| Select Case e.Item.ItemType |
| Case GridItemType.Header |
| Dim lnkLegend As HyperLink = DirectCast(e.Item.FindControl("lnkLegend"), HyperLink) |
| rttmLegend.TargetControls.Add(lnkLegend.ClientID, True) |
| Case GridItemType.Item, GridItemType.AlternatingItem |
| With DirectCast(e.Item.DataItem, Prospect) |
| DirectCast(e.Item.FindControl("imgCalled"), Image).Visible = .IsCalled |
| DirectCast(e.Item.FindControl("imgRegistered"), Image).Visible = .IsRegistered |
| DirectCast(e.Item.FindControl("imgConfirmed"), Image).Visible = .IsConfirmed |
| DirectCast(e.Item.FindControl("imgFinalized"), Image).Visible = .IsFinalized |
| Dim imgHasComment As Image = DirectCast(e.Item.FindControl("imgHasComment"), Image) |
| imgHasComment.Visible = .HasRecruiterComment |
| If imgHasComment.Visible Then |
| rttmRecruiterComments.TargetControls.Add(imgHasComment.ClientID, .BACID, True) |
| End If |
| End Select |
| End Sub |
protected void UpdateAll_Clicked(object sender, EventArgs e) { try { WeatherForecast w = new WeatherForecast(); WeatherForecast orig_w = new WeatherForecast(); foreach (GridDataItem item in RadGrid1.EditItems) { GridEditableItem editedItem = (item.OwnerTableView.EditMode == GridEditMode.InPlace) ? item : (GridEditableItem)item.EditFormItem; Hashtable newValues = new Hashtable(); //The GridTableView will fill the values from all editable columns in the hash RadGrid1.MasterTableView.ExtractValuesFromItem(newValues, editedItem); newValues["Temp"] = (editedItem.FindControl("txtTemp") as TextBox).Text; newValues["Temp2"] = (editedItem.FindControl("txtTemp2") as TextBox).Text; newValues["ShortText"] = (editedItem.FindControl("txtShortText") as TextBox).Text; newValues["Pop"] = (editedItem.FindControl("txtPop") as TextBox).Text; newValues["Manual"] = (editedItem.FindControl("radioManualEdit") as RadioButton).Checked; newValues["ConditionId"] = (editedItem.FindControl("listWeather") as RadComboBox).SelectedItem.Value; newValues["UvIndex"] = (editedItem.FindControl("listUvIndex") as DropDownList).SelectedItem.Value; w.Id = Convert.ToInt32(editedItem.GetDataKeyValue("Id")); w.Temp = Convert.ToInt32(newValues["Temp"]); w.Temp2 = Convert.ToInt32(newValues["Temp2"]); w.ConditionId = Convert.ToInt32(newValues["ConditionId"]); w.ShortText = Convert.ToString(newValues["ShortText"]); if (string.IsNullOrEmpty(Convert.ToString(newValues["Pop"]))) { w.Pop = null; } else { w.Pop = Convert.ToInt32(newValues["Pop"]); } w.Manual = Convert.ToBoolean(newValues["Manual"]); w.UvIndex = Convert.ToInt32(newValues["UvIndex"]); w.UvText = WeatherForecast.GetUvText(w.UvIndex); // TODO: implement day of week editing // w.DayOfWeek = Convert.ToString(newValues["DayOfWeek"]); orig_w.Id = w.Id; orig_w.Temp = Convert.ToInt32(editedItem.SavedOldValues["Temp"]); orig_w.Temp2 = Convert.ToInt32(editedItem.SavedOldValues["Temp2"]); orig_w.ConditionId = Convert.ToInt32(editedItem.SavedOldValues["ConditionId"]); orig_w.ShortText = Convert.ToString(editedItem.SavedOldValues["ShortText"]); if (string.IsNullOrEmpty(Convert.ToString(editedItem.SavedOldValues["Pop"]))) { orig_w.Pop = null; } else { orig_w.Pop = Convert.ToInt32(editedItem.SavedOldValues["Pop"]); } orig_w.Manual = Convert.ToBoolean(editedItem.SavedOldValues["Manual"]); orig_w.UvIndex = Convert.ToInt32(editedItem.SavedOldValues["UvIndex"]); orig_w.UvText = WeatherForecast.GetUvText(orig_w.UvIndex); // wDAO.UpdateWeather(w, orig_w); editedItem.Edit = false; } } catch (Exception ex) { Common.FlowFunctions.ShowErrorMessage(RadAjaxManager1, "Error updating weather: " + ex.Message, true); } setSelection = true; RadGridCity.Rebind(); RadGrid1.Rebind(); }<telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="0" GridLines="None" AllowSorting="false" AutoGenerateColumns="False" AllowPaging="true" PageSize="20" AllowAutomaticDeletes="false" AllowAutomaticUpdates="false" OnPreRender="RadGrid1_PreRender" OnSortCommand="RadGrid1_SortCommand" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand" OnItemDataBound="RadGrid1_ItemDataBound" > <ClientSettings > <ClientEvents OnKeyPress="keyPressedStopEnter" /> </ClientSettings> <PagerStyle AlwaysVisible="false" /> <ItemStyle CssClass="report_col_B" /> <AlternatingItemStyle CssClass="report_col_A" /> <MasterTableView DataKeyNames="Id" EditMode="InPlace" TableLayout="Fixed" CommandItemDisplay="Top"> <Columns> <telerik:GridCheckBoxColumn DataField="Manual" DataType="System.Boolean" HeaderText="Source" SortExpression="Manual" UniqueName="Manual" Display="false"> </telerik:GridCheckBoxColumn> <telerik:GridBoundColumn DataField="LocationCode" UniqueName="LocationCode" HeaderText="Location Code" Visible="false" ></telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="LocationName" DataType="System.String" UniqueName="LocationName" Visible="false" HeaderText="Location" ></telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="ConditionId" UniqueName="ConditionId" HeaderText="Icon" AllowSorting="false" Visible="false" ></telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="TempLabel" UniqueName="TempLabel" Visible="false" AllowSorting="false" ></telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Temp2Label" UniqueName="Temp2Label" Visible="false" AllowSorting="false" ></telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Temp" UniqueName="Temp" HeaderText="Temp" AllowSorting="false" Visible="false" HeaderTooltip="The high for daily forecasts." ></telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Temp2" UniqueName="Temp2" HeaderText="Temp 2" AllowSorting="false" Visible="false" HeaderTooltip="The low for daily forecasts and 'Feels Like' for current and hourly." ></telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="ShortText" UniqueName="ShortText" HeaderText="Short Text" Visible="false" AllowSorting="false" ></telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Pop" UniqueName="Pop" HeaderText="P.O.P." AllowSorting="false" Visible="false" HeaderTooltip="Probability of Precipitation" ></telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="UvIndex" UniqueName="UvIndex" HeaderText="UV Index" Visible="false" AllowSorting="false" ></telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="UvText" UniqueName="UvText" HeaderText="UV Text" Visible="false" AllowSorting="false" ></telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="ModifiedDate" UniqueName="ModifiedDate" HeaderText="Last Updated" SortExpression="ModifiedDate" ReadOnly="true"> <ItemStyle CssClass="smc_form" /> </telerik:GridBoundColumn> </Columns> <ItemTemplate> <table cellpadding="0" cellspacing="0" > <col width="140px" /> <col width="30px" /> <col width="190px" /> <col width="80px" /> <col width="80px" /> <col width="50px" /> <col width="120px" /> <col width="80px" /> <col width="80px" /> <tr> <td rowspan="2"> <h2><%# ForecastDayDisplay(Eval("ForecastName"), Eval("DayOfWeek"))%></h2> <%#Eval("ModifiedDate", "{0:g}")%> </td> <td rowspan="2"><asp:ImageButton ID="ManualToggleButton" Height="24px" runat="server" CausesValidation="false" /></td> <td rowspan="2"><%# Eval("ConditionText")%></td> <td align="right" ><%# Eval("TempLabel")%></td> <td><%# Eval("Temp")%> <span class="smc_bodybold">°C</span></td> <td>Text:</td> <td><%# Eval("ShortText")%></td> <td align="right" >UV Index:</td> <td><%# NullIntDisplay(Eval("UvIndex"), "")%></td> </tr> <tr> <td align="right" ><%# Eval("Temp2Label")%></td> <td ><%# Eval("Temp2")%> <span class="smc_bodybold">°C</span></td> <td><span title="Probability of precipitation" style="cursor: help" >P.O.P.:</span></td> <td><%# NullIntDisplay(Eval("Pop"), "%")%></td> <td align="right" >UV Text::</td> <td><%# Eval("UvText")%></td> </tr> </table> </ItemTemplate> <CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="false" /> <CommandItemTemplate> <table> <tr> <td style="font-size: 13px; padding: 10px 10px; text-align: left; white-space: nowrap; font-weight: bold"> <asp:Label ID="labelCityName" runat="server" Text="Select" ></asp:Label> <br /> City Weather Details </td> <td><br /> <asp:Button ID="btnUpdateAll" CssClass="smc_form" runat="server" Text="Save Now >" CommandName="UpdateAll" Visible="true" OnClick="UpdateAll_Clicked" /> </td> <td style="width: 50px;"> </td> <td style="font-size: 11px; padding: 10px 10px; text-align: left; white-space: nowrap; font-weight: bold"> <asp:Panel ID="panelDataSources" runat="server"> <asp:Label runat="server" ID="Label1" Text="Data Source:"></asp:Label> <br /> <asp:ImageButton Height="32" ID="btnAllManual" CommandName="SetAllAutoOff" ImageUrl="~/images/icons/auto_off.png" runat="server" ToolTip="Set all forecasts to Manual" AlternateText="All Manual" OnClientClick="return confirm('Are you sure you want to set all forecasts to Manual?');" /> <asp:ImageButton Height="32" ID="btnAllAutomated" CommandName="SetAllAutoOn" ImageUrl="~/images/icons/auto_on.png" runat="server" ToolTip="Set all forecasts to Data Feed" AlternateText="All Auto" OnClientClick="return confirm('Are you sure you want to set all forecasts to Data Feed?');" /> </asp:Panel> </td> </tr> </table> </CommandItemTemplate> <EditItemTemplate> <table cellpadding="0" cellspacing="0" > <col width="140px" /> <col width="100px" /> <col width="190px" /> <col width="80px" /> <col width="80px" /> <col width="60px" /> <col width="140px" /> <col width="120px" /> <tr> <td rowspan="2"> <h2><%# ForecastDayDisplay(Eval("ForecastName"), Eval("DayOfWeek"))%></h2> <span class="smc_body"><%#Eval("ModifiedDate", "{0:g}")%></span> </td> <td rowspan="2"> <asp:RadioButton ID="radioManualEdit" runat="server" Text="Manual" Checked='<%# Bind("Manual") %>' GroupName="manualAuto" /> <br /> <asp:RadioButton ID="radioDataFeedEdit" runat="server" Text="Data Feed" Checked='<%# (!(Convert.ToBoolean(Eval("Manual")))) %>' GroupName="manualAuto" /> </td> <td rowspan="2"> <telerik:RadComboBox ID="listWeather" CssClass="smc_form" AppendDataBoundItems="true" DataSourceID="weatherListDataSource" DataTextField="weatherName" DataValueField="weatherId" Width="190px" runat="server" DropDownWidth="250px" Height="200px" SelectedValue='<%# Bind("ConditionId")%>' > <Items> <telerik:RadComboBoxItem Text="-" Value="0" /> </Items> </telerik:RadComboBox> </td> <td align="right"><%# Eval("TempLabel")%></td> <td> <asp:TextBox ID="txtTemp" runat="server" Width="25px" Text='<%# Bind("Temp")%>' CssClass="smc_form flow_right" MaxLength="5" AutoCompleteType="None" > </asp:TextBox> <span class="smc_bodybold">°C</span> </td> <td align="right">Text:</td> <td> <asp:TextBox ID="txtShortText" runat="server" Width="100px" Text='<%# Bind("ShortText")%>' CssClass="smc_form" MaxLength="128" > </asp:TextBox> </td> <td rowspan="2">UV Index: <br /> <asp:DropDownList ID="listUvIndex" runat="server" CssClass="smc_form" Width="120px" SelectedValue='<%# Bind("UvIndex")%>' > <asp:ListItem Text="-" Value="-1"></asp:ListItem> <asp:ListItem Text="0 - Low" Value="0"></asp:ListItem> <asp:ListItem Text="1 - Low" Value="1"></asp:ListItem> <asp:ListItem Text="2 - Low" Value="2"></asp:ListItem> <asp:ListItem Text="3 - Moderate" Value="3"></asp:ListItem> <asp:ListItem Text="4 - Moderate" Value="4"></asp:ListItem> <asp:ListItem Text="5 - Moderate" Value="5"></asp:ListItem> <asp:ListItem Text="6 - High" Value="6"></asp:ListItem> <asp:ListItem Text="7 - High" Value="7"></asp:ListItem> <asp:ListItem Text="8 - Very High" Value="8"></asp:ListItem> <asp:ListItem Text="9 - Veru High" Value="9"></asp:ListItem> <asp:ListItem Text="10 - Very High" Value="10"></asp:ListItem> <asp:ListItem Text="11+ - Extreme" Value="11"></asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <td align="right"><%# Eval("Temp2Label")%></td> <td> <asp:TextBox ID="txtTemp2" runat="server" Width="25px" Text='<%# Bind("Temp2")%>' CssClass="smc_form flow_right" MaxLength="5" AutoCompleteType="None" > </asp:TextBox> <span class="smc_bodybold">°C</span> </td> <td align="right">P.O.P.:</td> <td> <asp:TextBox ID="txtPop" runat="server" Width="25px" Text='<%# Bind("Pop")%>' CssClass="smc_form flow_right" MaxLength="5" AutoCompleteType="None"> </asp:TextBox> <span class="smc_bodybold">%</span> </td> <td></td> </tr> </table> </EditItemTemplate> </MasterTableView> </telerik:RadGrid><asp:Content ID="__functionLeft" ContentPlaceHolderID="MainContent" runat="Server"><asp:UpdatePanel ID="__upDatePanel" runat="server"> <ContentTemplate> <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> <script type="text/javascript"> // <![CDATA[ //On insert and update buttons click temporarily disables ajax to perform upload actions function conditionalPostback(sender, eventArgs) { var theRegexp = new RegExp("\.UpdateButton$|\.PerformInsertButton$", "ig"); if (eventArgs.get_eventTarget().match(theRegexp)) { var upload = $find(window['UploadId']); //AJAX is disabled only if file is selected for upload if (upload.getFileInputs()[0].value != "") { eventArgs.set_enableAjax(false); } } } function validateRadUpload(source, e) { e.IsValid = false; var upload = $find(source.parentNode.getElementsByTagName('div')[0].id); var inputs = upload.getFileInputs(); for (var i = 0; i < inputs.length; i++) { //check for empty string or invalid extension if (inputs[i].value != "" && upload.isExtensionValid(inputs[i].value)) { e.IsValid = true; break; } } } // ]]> </script> </telerik:RadCodeBlock> <telerik:RadGrid ID="__linksRadGrid" runat="server" AllowMultiRowEdit="false" ShowStatusBar="true" GridLines="None" AllowPaging="False" AllowAutomaticUpdates="false" AllowAutomaticInserts="false" OnPreRender="LinksGridView_PreRender" OnItemCreated="LinksGridView_ItemCreated" OnNeedDataSource="LinksRadGrid_NeedDataSource" OnInsertCommand="LinksRadGrid_InsertCommand" OnUpdateCommand="LinksRadGrid_UpdateCommand" OnDeleteCommand="LinksRadGrid_DeleteCommand" OnItemDataBound="LinksRadGrid_ItemDataBound" OnItemCommand="LinksRadGrid_ItemCommand" OnEditCommand="LinksRadGrid_EditCommand" AllowSorting="true" Skin="Transparent" Width="450px" > <MasterTableView AutoGenerateColumns="False" DataKeyNames="IdAttachment" CommandItemDisplay="Bottom" > <PagerStyle Mode="NextPrevAndNumeric" /> <CommandItemTemplate> <div style="padding: 5px 5px;"> <asp:ImageButton ID="imgInsert" runat="server" CommandName="InitInsert" AlternateText="Insert New Record" ToolTip = "Insert New Record" /> <asp:ImageButton ID="imgRefresh" runat="server" CommandName="RebindGrid" AlternateText="Refresh the grid" ToolTip = "Refresh the grid" /> </div> </CommandItemTemplate> <Columns> <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditAttachmentLinks" ItemStyle-Width="30px" ItemStyle-HorizontalAlign="Center"/> <telerik:GridBoundColumn DataField="Title" DataType="System.String" HeaderText="Title" SortExpression="Title" UniqueName="Title"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Description" DataType="System.String" HeaderText="Description" SortExpression="Description" UniqueName="Description"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="AttachmentType" DataType="System.String" HeaderText="AttachmentType" SortExpression="AttachmentType" UniqueName="AttachmentType" Display="false"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Url" DataType="System.String" HeaderText="Url" SortExpression="Url" UniqueName="URL" Display="false"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn HeaderText="Type" UniqueName="Type" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" > <ItemTemplate> <asp:ImageButton ID="__attachedTypeImageButton" runat="server" /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridButtonColumn CommandName="Delete" ButtonType="ImageButton" UniqueName="DeleteAttachmentLinks" ConfirmText="Delete this record?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ItemStyle-Width="30px" ItemStyle-HorizontalAlign="Center"/> </Columns> <EditFormSettings EditFormType="Template"> <EditColumn UniqueName="EditCommandColumn1"> </EditColumn> <FormTemplate> <table cellspacing="2" cellpadding="1" width="100%" border="0"> <tr> <td> <asp:Label ID="__titleLabel" runat="server" Text="Title"> </asp:Label> </td> <td> <asp:TextBox ID="__titleTextBox" runat="server" Width="100px" Text='<%# Bind("Title") %>' > </asp:TextBox> <span style="color:Red; font-weight:bold">*</span> <br /> <asp:RequiredFieldValidator ID="__titleTextBoxRFValidator" runat="server" ControlToValidate="__titleTextBox" Display="Dynamic" ErrorMessage="Please, enter a title!" SetFocusOnError="true" /> </td> </tr> <tr> <td> <asp:Label ID="__decriptionLabel" runat="server" Text="Description"> </asp:Label> </td> <td> <asp:TextBox ID="__decriptionTextBox" runat="server" Width="100px" TextMode="MultiLine" Rows="4" Text='<%# Bind("Description") %>'> </asp:TextBox> <span style="color:Red; font-weight:bold">*</span> <br /> <asp:RequiredFieldValidator ID="__decriptionTextBoxRFValidator" runat="server" ControlToValidate="__decriptionTextBox" Display="Dynamic" ErrorMessage="Please, enter a description!" SetFocusOnError="true" /> </td> </tr> <tr> <td> <asp:Label ID="__URLLabel" runat="server" Text="URL"> </asp:Label> </td> <td> <asp:TextBox ID="__urlTextBox" runat="server" Width="255px" Text='<%# Bind("URL") %>' > </asp:TextBox> </td> </tr> <tr> <td colspan="2"> <asp:Label ID="__orLabel" runat="server" Text="or"> </asp:Label> </td> </tr> <tr> <td> <asp:Label ID="__fileUploadLabel" runat="server" Text="File"> </asp:Label> </td> <td> <div id="__fileUploadDiv" runat="server"> <telerik:RadUpload ID="__fileUpload" runat="server" ControlObjectsVisibility="None" MaxFileInputsCount="1" /> </div> </td> </tr> <tr> <td align="right" colspan="2"> <asp:Button ID="btnUpdate" runat="server" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' CausesValidation="True" > </asp:Button > <asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="False" CommandName="Cancel"> </asp:Button > </td> </tr> </table> </FormTemplate> </EditFormSettings> </MasterTableView> </telerik:RadGrid> </ContentTemplate> </asp:UpdatePanel><script type="text/javascript" > function LinksFileUpload_OnChange(clientidTextBox) { document.getElementById(clientidTextBox).value = ""; } function LinksUrlTextBox_OnChange(clientIdDIVFileUpload) { //We couldn't change the input file value, so we reset the DIV container document.getElementById(clientIdDIVFileUpload).innerHTML = document.getElementById(clientIdDIVFileUpload).innerHTML; } </script></asp:Content>using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;using System.ComponentModel;using Telerik.Web.UI;using System.Text;using System.Web.UI.HtmlControls;using System.IO;public class ListHelper { public static DataTable ToDataTable<T>(IList<T> data) { PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(T)); DataTable table = new DataTable(); for (int i = 0; i < props.Count; i++) { PropertyDescriptor prop = props[i]; table.Columns.Add(prop.Name, prop.PropertyType); } object[] values = new object[props.Count]; foreach (T item in data) { for (int i = 0; i < values.Length; i++) { values[i] = props[i].GetValue(item); } table.Rows.Add(values); } return table; }}public class GWAttachment { #region Accessor private string _title; public string Title { get { return this._title; } set { this._title = value; } } private string _description; public string Description { get { return this._title; } set { this._title = value; } } private string _url; public string Url { get { return this._url; } set { this._url = value; } } private string _fileName; public string FileName { get { return this._fileName; } set { this._fileName = value; } } private int _idAttachment; public int IdAttachment { get { return this._idAttachment; } set { this._idAttachment = value; } } private int _attachmentType; public int AttachmentType { get { return this._attachmentType; } set { this._attachmentType = value; } } #endregion}public partial class Default2 : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } #region Links protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridEditableItem && e.Item.IsInEditMode) { } } #region DataSource protected void LinksObjectDataSource_Selecting(object sender, ObjectDataSourceSelectingEventArgs e) { } #endregion #region Gridview protected void LinksGridView_PreRender(object sender, EventArgs e) { } protected void LinksGridView_ItemCreated(object sender, GridItemEventArgs e) { } protected void DisableControls(ControlCollection controls) { foreach (Control c in controls) { if (c is WebControl) { ((WebControl)c).Enabled = false; } DisableControls(c.Controls); } } protected void LinksRadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { GWAttachment att1 = new GWAttachment(); att1.IdAttachment = 1; att1.Title = "Test 1"; att1.Description = "Decription 1"; att1.Url = "http://www.google.com"; att1.AttachmentType = 3; GWAttachment att2 = new GWAttachment(); att2.IdAttachment = 2; att2.Title = "Test 2"; att2.Description = "Decription 2"; att2.Url = "http://www.google.com/test"; att2.AttachmentType = 4; List<GWAttachment> attachmentList = new List<GWAttachment>(); attachmentList.Add(att1); attachmentList.Add(att2); DataTable dt = ListHelper.ToDataTable<GWAttachment>(attachmentList); this.__linksRadGrid.DataSource = dt; } protected void LinksRadGrid_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem) { GridDataItem gridDataItem = (GridDataItem)e.Item; int attachedType = int.Parse(gridDataItem["AttachmentType"].Text); ImageButton image = (ImageButton)gridDataItem["Type"].FindControl("__attachedTypeImageButton"); if (attachedType == 3 && !string.IsNullOrEmpty(gridDataItem["URL"].Text)) { int idDocument = this.GetDocumentLinksId(gridDataItem["URL"].Text); if (idDocument > 0) { image.OnClientClick = this.BuildDocumentPopupScript(idDocument); } else { this.ShowImageError(image, "Error : unable to parse the internal document id! Please correct the URL."); } } else if (attachedType == 4 && !string.IsNullOrEmpty(gridDataItem["URL"].Text)) { image.OnClientClick = this.WindowsOpenPopup(gridDataItem["URL"].Text); } else if (attachedType == 5) { int idAttachment = int.Parse(gridDataItem.GetDataKeyValue("IdAttachment").ToString()); image.OnClientClick = this.GetAttachmentLinksUrl(idAttachment); } else { } } else if (e.Item is GridEditFormItem && e.Item.IsInEditMode) { GridEditFormItem editItem = e.Item as GridEditFormItem; TextBox urlTxtBox = (TextBox)editItem.FindControl("__urlTextBox"); RadUpload linksFileUpload = (RadUpload)editItem.FindControl("__fileUpload"); Control linksFileUploadDIV = (Control)editItem.FindControl("__fileUploadDiv"); if (urlTxtBox != null && linksFileUpload != null && linksFileUploadDIV != null) { // It is forbidden to reset a FileUpload, so we reset the dive container! string onChangeEventUrlTxtBox = "LinksUrlTextBox_OnChange('" + linksFileUploadDIV.ClientID + "')"; string onChangeEventLinksFileUpload = "LinksFileUpload_OnChange('" + urlTxtBox.ClientID + "')"; urlTxtBox.Attributes.Add("onchange", onChangeEventUrlTxtBox); linksFileUpload.Attributes.Add("onchange", onChangeEventLinksFileUpload); } } } #region Attachment file protected String GetAttachmentLinksUrl(int idAttachment) { String page = "~/Attachment.aspx"; page = VirtualPathUtility.ToAbsolute(page); StringBuilder url = new StringBuilder(page); url.AppendFormat("?IdAttachment={0}&Type={1}", idAttachment, 3); string javaScript = "javascript:window.open('{0}','popup{1}','width=650,height=750,scrollbars=yes');return false;"; return String.Format(javaScript, url.ToString(), idAttachment); } #endregion protected void LinksRadGrid_ItemCommand(object source, GridCommandEventArgs e) { if (e.CommandName == RadGrid.DownloadAttachmentCommandName) { GridEditFormItem editFormItem = (GridEditFormItem)e.Item; } } protected void LinksRadGrid_EditCommand(object source, GridCommandEventArgs e) { if (e.CommandName == RadGrid.EditCommandName && e.Item is GridDataItem) { GridDataItem gridDataItem = (GridDataItem)e.Item; TextBox urlTxtBox = (TextBox)gridDataItem.FindControl("__urlTextBox"); RadUpload linksFileUpload = (RadUpload)gridDataItem.FindControl("__fileUpload"); if (urlTxtBox != null && linksFileUpload.UploadedFiles != null) { urlTxtBox.Attributes.Add("onchange", "LinksUrlTextBox_OnChange(" + linksFileUpload.ClientID + ")"); linksFileUpload.Attributes.Add("onchange", "LinksFileUpload_OnChange(" + urlTxtBox.ClientID + ")"); } } } protected void LinksRadGrid_InsertCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == RadGrid.PerformInsertCommandName) { if (e.Item is GridEditFormItem) { GridEditFormItem gridDataItem = (GridEditFormItem)e.Item; this.SaveAttachment(gridDataItem, false); this.__linksRadGrid.Rebind(); } } } protected void LinksRadGrid_UpdateCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == RadGrid.UpdateCommandName) { if (e.Item is GridEditFormItem) { GridEditFormItem gridDataItem = (GridEditFormItem)e.Item; this.SaveAttachment(gridDataItem, true); this.__linksRadGrid.Rebind(); } } } protected void LinksRadGrid_DeleteCommand(object sender, GridCommandEventArgs e) { GridEditableItem editedItem = e.Item as GridEditableItem; } #region Save the Attachment of the document private void SaveAttachment(GridEditFormItem gridDataItem, bool isAttachmentUpdate) { int idAttachment = 0; if (isAttachmentUpdate) { idAttachment = Convert.ToInt32(gridDataItem.GetDataKeyValue("IdAttachment")); } TextBox titleTxtBox = (TextBox)gridDataItem.FindControl("__titleTextBox"); TextBox descriptionTxtBox = (TextBox)gridDataItem.FindControl("__decriptionTextBox"); TextBox urlTxtBox = (TextBox)gridDataItem.FindControl("__urlTextBox"); RadUpload linksFileUpload = (RadUpload)gridDataItem.FindControl("__fileUpload"); string title = string.Empty; string description = string.Empty; string url = string.Empty; if (titleTxtBox != null) title = titleTxtBox.Text; if (descriptionTxtBox != null) description = descriptionTxtBox.Text; if (urlTxtBox != null) url = urlTxtBox.Text; GWAttachment attachment = new GWAttachment(); attachment.Title = title; attachment.Description = description; attachment.Url = url; Stream file = null; if (linksFileUpload != null && linksFileUpload.UploadedFiles != null && urlTxtBox != null && string.IsNullOrEmpty(url)) { attachment.AttachmentType = 5; if (linksFileUpload.UploadedFiles != null && linksFileUpload.UploadedFiles.Count == 1) { UploadedFile uploadedFile = linksFileUpload.UploadedFiles[0]; file = uploadedFile.InputStream; } } //If a file is also defined, we take only the url when it exist too if (urlTxtBox != null && !string.IsNullOrEmpty(url)) { if (url.Contains(HttpContext.Current.Request.Url.Host)) { attachment.AttachmentType = 3; } else { attachment.AttachmentType = 4; } } } #endregion private string BuildDocumentPopupScript(int documentId) { string popupScript = string.Empty; string clientUrl = ResolveClientUrl("~/DetailPopup.aspx"); clientUrl = string.Format("{0}?idDocument={1}", clientUrl, documentId); popupScript = string.Format("javascript:window.open('{0}','{1}','width=800,height=750,resizable=yes,scrollbars=yes');return false;", clientUrl, 10); return popupScript; } private string WindowsOpenPopup(string url) { string popupScript = string.Empty; popupScript = string.Format(@"javascript:window.open('{0}','{1}','width=800,height=750,resizable=yes,scrollbars=yes');return false;", url, url); return popupScript; } private int GetDocumentLinksId(string url) { int idDocumentLinks = -1; var uri = new Uri(url); var query = HttpUtility.ParseQueryString(uri.Query); return idDocumentLinks; } private ImageButton ShowImageError(ImageButton imageBut, string message) { return imageBut; } #endregion #endregion}