Posts

Required Field Validator for CheckBoxList

When you use asp check box list and want to apply required field validator then follow below example.   <asp:CheckBoxList ID = "chkDemoList" runat = "server" > <asp:ListItem Text = "India" Value = "IN" ></asp:ListItem> <asp:ListItem Text = "United States of Americs" Value = "USA" ></asp:ListItem> <asp:ListItem Text = "Japan" Value = "JP" ></asp:ListItem>   </asp:CheckBoxList> <asp:CustomValidator runat = "server" ID = "cv DemoList " ClientValidationFunction = "Validate DemoList " ErrorMessage = "Required Field" ></asp:CustomValidator> // javascript to add to your aspx page function Validate DemoList (source, args) { var chkListModules= document.getElementById (' <%= chkDemoList . ClientID %>'); var chkListinputs = chkListModules.getElementsByTagName("in...

RadGrid Row Select

If you want to select row in RadGrid then set some RadGrid properties like              <ClientSettings Selecting-AllowRowSelect="true" Selecting-EnableDragToSelectRows="false">              <MasterTableView DataKeyNames="ID"> If you want to select first row then use below code                if (RadGrid.Items.Count > 0)                 {                     RadGrid.MasterTableView.Items[0].Selected = true;                 } If you want to select any row on that basis of data key name then use below code         ...

SharePoint 2010 Consume SP List Data to Grid View

There is some data in your SPList and you want to show those list items in a grid view then follow below example. first of all create a visual webpart and put a grid view into that like: <asp:GridView ID="grdDocuments" runat="server" AutoGenerateColumns="false" > <Columns> <asp:BoundField DataField="ID" HeaderText="ID"></asp:BoundField> <asp:BoundField DataField="Name" HeaderText="Name"></asp:BoundField> </Columns> </asp:GridView> Now we have to do some code for bind data in this grid. void BindDocuments()         {             SPWeb mySite = SPContext.Current.Web;             SPList myList = mySite.Lists[" MyDocsLibName "];             SPListItemCollection items = myList.Items;             //Here we will make a datatable and we will put our document library data to the data table ...

SharePoint Reset Unique Permissions (Inherit Permissions) on a List/Library Using PowerShell

## CLEAR AND ADD SNAP IN ##    cls Remove-PSSnapin Microsoft.SharePoint. Powershell -ErrorAction SilentlyContinue Add-PSSnapin Microsoft.SharePoint. Powershell }      ## ASSIGN VARIABLE ##   $webUrl  =  $args [0]  $listName  =   $args [1]  $listInherits  =  $args [2]    # Varibale to hold document count   $count  = 0        ##  OPEN OBJECTS & RESTORE INHERITANCE ##      try  {       # Open the web and list objects        $web  = Get - SPWeb  $webUrl        $list  =  $web .Lists[ $listName ]         # If the list should inherit, reset the role inheritance     ...

C# generate random string of different length

If you want to generate random strings of different different lengths, than use below function. Here size is an input variable for length of string.      public static string RandomString( int size)       {             string builder = string .Empty;              Random random = new Random ();              char ch;              for ( int i = 0; i < size; i++)              {                  ch = Convert .ToChar( Convert .ToInt32( Math .Floor(26 * random.NextDouble() + 65)));                  builder +...

C# generate random numbers in a range

 If you want to generate a random nomber in a range than use below function. it has two inputs "min" -  enter min value of your range and "max" - enter max value of your range.  public static int RandomNumber( int min , int max )          {              Random random = new Random ();              return random.Next(min, max);          } Here in above function Random is a class. this is exist in .net framework by default. you should only use namespace "using System" for this.

SharePoint 2010 Enable Session State

If you trying to store data to session or using session in your user control, application page, webpart etc. then some time it may encounter an error below if session property not set to true in web.config. Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the..... first enable session state to true in web.config <pages enableSessionState="true" enableViewState="true" enableViewStateMac="true" validateRequest="false" pageParserFilterType="Microsoft.SharePoint.ApplicationRuntime.SPPageParserFilter, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" asyncTimeout="7"> second add name session to modules in web.config  <modules runAllManagedModulesForAllRequests="true"> ---- -...