daily pastebin goal
58%
SHARE
TWEET

Untitled

a guest Jan 15th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. protected void cvAccountNumber_ServerValidate(object source, ServerValidateEventArgs args)
  2. {
  3.     TextBox txtAccountNumber = (TextBox)RadGrid1.MasterTableView.GetInsertItem().FindControl("txtAccountNumber");
  4.  
  5.     List<GridDataItem> Items = (from item in RadGrid1.Items.Cast<GridDataItem>()
  6.                                 where item["AccountNumberView"].Text == txtAccountNumber.Text
  7.                                 select item).ToList();
  8.  
  9.     args.IsValid = Items.Count() == 0;
  10. }
  11.    
  12. Sort By Status: <asp:DropDownList ID="dd_Status" runat="server" Width="150px"
  13.     onselectedindexchanged="dd_Status_SelectedIndexChanged"
  14.     AutoPostBack="True">
  15.     <asp:ListItem Text="All" Value="0" Selected="True"></asp:ListItem>
  16.     <asp:ListItem Text="Active" Value="True"></asp:ListItem>
  17.     <asp:ListItem Text="Inactive" Value="False"></asp:ListItem>
  18. </asp:DropDownList>
  19.  
  20. <br /><br />
  21.  
  22. <telerik:RadGrid ID="RadGrid1" runat="server" Skin="Vista" Width="500px"
  23.     GridLines="None" AllowFilteringByColumn="False" AllowSorting="True" OnExportCellFormatting="RadGrid1_ExportCellFormatting" DataSourceID="SqlDataSource1"
  24.      AllowAutomaticDeletes="true" AllowAutomaticUpdates="True" AutoGenerateEditColumn="True"  AutoGenerateDeleteColumn="true" OnItemCommand="RadGrid1_ItemCommand" >
  25.     <MasterTableView AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" ItemStyle-HorizontalAlign="Left" CommandItemDisplay="TopAndBottom">
  26.         <Columns>
  27.             <telerik:GridTemplateColumn HeaderText="ID" SortExpression="ID" UniqueName="ID" Visible="false" ReadOnly="true">
  28.                 <ItemTemplate>
  29.                     <asp:Label ID="lblIDView" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
  30.                 </ItemTemplate>
  31.             </telerik:GridTemplateColumn>
  32.             <telerik:GridTemplateColumn HeaderText="ID" SortExpression="IDEdit" UniqueName="IDEdit" Visible="false">
  33.                 <ItemTemplate />
  34.                 <EditItemTemplate>
  35.                     <asp:Label ID="lblID" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
  36.                 </EditItemTemplate>
  37.             </telerik:GridTemplateColumn>
  38.             <telerik:GridBoundColumn DataField="AccountNumber" HeaderText="Sapphire Account Number"
  39.                 SortExpression="AccountNumber" UniqueName="AccountNumberView" ReadOnly="true" ItemStyle-Width="400">
  40.             </telerik:GridBoundColumn>
  41.             <telerik:GridTemplateColumn HeaderText="Sapphire Account Number" SortExpression="AccountNumber" UniqueName="AccountNumber" Visible="false">
  42.                 <ItemTemplate />
  43.                 <EditItemTemplate>
  44.                     <asp:Textbox ID="txtAccountNumber" runat="server" Text='<%# Bind("AccountNumber") %>' />
  45.                     <asp:RequiredFieldValidator ID="rfvAccountNumber" ControlToValidate="txtAccountNumber"
  46.                         ErrorMessage="Sapphire Account Number is required" runat="server" ForeColor="Red"></asp:RequiredFieldValidator>
  47.                     <asp:CustomValidator ID="cvAccountNumber" runat="server" ErrorMessage="Sapphire Account Number already exists"
  48.                         ControlToValidate="txtAccountNumber" ForeColor="Red" OnServerValidate="cvAccountNumber_ServerValidate"></asp:CustomValidator>
  49.                 </EditItemTemplate>
  50.             </telerik:GridTemplateColumn>
  51.             <telerik:GridTemplateColumn HeaderText="Active" SortExpression="Active" UniqueName="Active" ItemStyle-Width="100" Visible="false">
  52.                 <ItemTemplate />
  53.                 <EditItemTemplate>
  54.                     <asp:CheckBox ID="cbActive" runat="server" Checked='<%# GenerateBindString(Container.DataItem) %>' />
  55.                 </EditItemTemplate>
  56.             </telerik:GridTemplateColumn>
  57.             <telerik:GridTemplateColumn HeaderText="Status" SortExpression="Active" UniqueName="Active" ItemStyle-Width="100">
  58.                 <ItemTemplate>
  59.                     <asp:Label ID="lblActive" runat="server" Text='<%# Convert.ToBoolean(GenerateBindString(Container.DataItem)) == true ? "Active" : "Inactive" %>'></asp:Label>
  60.                 </ItemTemplate>
  61.             </telerik:GridTemplateColumn>
  62.          </Columns>
  63.     </MasterTableView>
  64.     <ValidationSettings CommandsToValidate="PerformInsert,Update" />
  65.     <ClientSettings>
  66.         <Selecting AllowRowSelect="True" />
  67.     </ClientSettings>
  68. </telerik:RadGrid>
  69.  
  70. <asp:SqlDataSource ID="SqlDataSource1" runat="server"
  71.     ConnectionString="<%$ ConnectionStrings:LBCust %>"
  72.     SelectCommand="SELECT * FROM [LBX_Portal_AccountNumbers] WHERE ([Site] = @Site) AND (Active=@Active OR @Active = '0') ORDER BY AccountNumber"
  73.     DeleteCommand="DELETE FROM [LBX_Portal_AccountNumbers] WHERE [ID] = @ID"
  74.     InsertCommand="INSERT INTO [LBX_Portal_AccountNumbers] ([AccountNumber], [Site], [Active]) VALUES (@AccountNumber, @Site, @Active)"
  75.     UpdateCommand="UPDATE [LBX_Portal_AccountNumbers] SET [AccountNumber] = @AccountNumber,  [Active] = @Active WHERE [ID] = @ID">
  76.     <SelectParameters>
  77.         <asp:ControlParameter ControlID="dd_Status" Name="Active"
  78.             PropertyName="SelectedValue" Type="String" />
  79.     </SelectParameters>
  80.     <DeleteParameters>
  81.         <asp:Parameter Name="ID" Type="Int32" />
  82.     </DeleteParameters>
  83.     <InsertParameters>
  84.         <asp:Parameter Name="AccountNumber" Type="String" />
  85.         <asp:Parameter Name="Site" Type="String" />
  86.         <asp:Parameter Name="Active" Type="Boolean" />
  87.     </InsertParameters>
  88.     <UpdateParameters>
  89.         <asp:Parameter Name="AccountNumber" Type="String" />
  90.         <asp:Parameter Name="Active" Type="Boolean" />
  91.     </UpdateParameters>
  92. </asp:SqlDataSource>
  93.    
  94. public partial class Admin_CustomerAccountManager : System.Web.UI.Page
  95. {
  96. public string SiteName = WebConfigurationManager.AppSettings["Site"].ToString();
  97.  
  98. protected void Page_Load(object sender, EventArgs e)
  99. {
  100.     Label LBXTitle = (Label)Master.FindControl("lbxTitle");
  101.  
  102.     LBXTitle.Text = "Customer Sapphire Account Number Manager";
  103.  
  104.     if (!this.IsPostBack)
  105.     {
  106.         SqlDataSource1.SelectParameters.Add("Site", DbType.String, SiteName);
  107.     }
  108. }
  109.  
  110. protected void dd_Status_SelectedIndexChanged(object sender, EventArgs e)
  111. {
  112.     RadGrid1.DataBind();
  113. }
  114.  
  115. protected bool GenerateBindString(object dataItem)
  116. {
  117.     bool ret = false;
  118.     // if column is null set checkbox.checked = false
  119.  
  120.     if ((DataBinder.Eval(dataItem, "Active")).ToString() == "")
  121.         ret = false;
  122.     else // set checkbox.checked to boolean value in Status column
  123.         ret = (bool)DataBinder.Eval(dataItem, "Active");
  124.  
  125.     return ret;
  126. }
  127.  
  128. protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
  129. {
  130.     Page.Validate();
  131.     if (Page.IsValid)
  132.     {
  133.         if (e.CommandName == "PerformInsert")
  134.         {
  135.             GridEditFormItem gridEditFormItem = (GridEditFormItem)e.Item;
  136.  
  137.             Label lblID = (Label)gridEditFormItem.FindControl("lblID");
  138.             TextBox txtAccountNumber = (TextBox)gridEditFormItem.FindControl("txtAccountNumber");
  139.             CheckBox cbActive = (CheckBox)gridEditFormItem.FindControl("cbActive");
  140.  
  141.             bool isActive = true;
  142.  
  143.             string SqlStr = "INSERT INTO [LBX_Portal_AccountNumbers] ([AccountNumber], [Site], [Active])";
  144.             SqlStr += " VALUES ('" + txtAccountNumber.Text + "'" + ", '" + SiteName + "'" + ", '" + isActive + "')";
  145.  
  146.             SqlDataSource1.InsertCommand = SqlStr;
  147.             SqlDataSource1.Insert();
  148.  
  149.         }
  150.  
  151.         if (e.CommandName == "Update")
  152.         {
  153.             GridEditFormItem gridEditFormItem = (GridEditFormItem)e.Item;
  154.  
  155.             Label lblID = (Label)gridEditFormItem.FindControl("lblID");
  156.             TextBox txtAccountNumber = (TextBox)gridEditFormItem.FindControl("txtAccountNumber");
  157.             CheckBox cbActive = (CheckBox)gridEditFormItem.FindControl("cbActive");
  158.  
  159.             bool isActive = false;
  160.  
  161.             if (cbActive.Checked)
  162.                 isActive = true;
  163.             else
  164.                 isActive = false;
  165.  
  166.             string SqlStr = "UPDATE [LBX_Portal_AccountNumbers] SET [AccountNumber] = '" + txtAccountNumber.Text;
  167.             SqlStr += "', [Active] = '" + isActive + "'  WHERE [ID] = " + lblID.Text;
  168.  
  169.             SqlDataSource1.UpdateCommand = SqlStr;
  170.             SqlDataSource1.Update();
  171.         }
  172.     }
  173. }
  174.  
  175. protected void cvAccountNumber_ServerValidate(object source, ServerValidateEventArgs args)
  176. {
  177.     TextBox txtAccountNumber = RadGrid1.FindControl("txtAccountNumber") as TextBox;
  178.     List<GridDataItem> Items = (from item in RadGrid1.Items.Cast<GridDataItem>()
  179.                                 where item["AccountNumberView"].Text == txtAccountNumber.Text
  180.                                 select item).ToList();
  181.  
  182.     args.IsValid = Items.Count() == 0;
  183. }
  184. }
  185.    
  186. protected void cvAccountNumber_ServerValidate(object source, ServerValidateEventArgs args)
  187.     {
  188.         string textToBeValidated = args.Value;
  189.     }
  190.    
  191. protected void cvAccountNumber_ServerValidate(object source, ServerValidateEventArgs args)
  192.     {
  193.         //find your editing row...
  194.         GridViewRow editedRow = RadGrid1.Rows[RadGrid1.EditIndex];
  195.         //now serch row for your control...
  196.         TextBox txtAccountNumber = (TextBox)editedRow.FindControl("txtAccountNumber");
  197.         TextBox txtId = (TextBox)editedRow.FindControl("txtId");
  198.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top