Wednesday 26 March 2014

date convert and short system date

DateTime todaydate1 =Convert.ToDateTime(drow["Created"]);
                     string  date=todaydate1.ToShortDateString();
                     string dtpresent = DateTime.Now.ToShortDateString();
                     if (dtpresent == date)
                     {
                     }


Compare the date /  Greater than date getting items  


               //Expiry date
                                    DateTime expire1 = Convert.ToDateTime(drow["Expires"]);
                                    string expire2 = expire1.ToShortDateString();

                                    string today_date = DateTime.Now.ToShortDateString();

                //today date

                                    DateTime theDateA = DateTime.Parse(today_date);
                                    DateTime theDateB = DateTime.Parse(expire2);

                                    if (theDateA < theDateB)
                                    {

Tuesday 11 March 2014

caml query for display in specific field to multiline textbox

 protected void Page_Load(object sender, EventArgs e)
        {
            SPSite site = SPContext.Current.Site;
            SPWeb web = site.OpenWeb();
         
            SPList li = web.Lists["JokeOfTheDay"];
            SPQuery q = new SPQuery();

 
            q.ViewFields = string.Concat(
                                  "<FieldRef Name='Title' />",
                                  "<FieldRef Name='jokename1' />",
                                  "<FieldRef Name='jokename2' />",
                               
            q.ViewFieldsOnly = true); // Fetch only the data that we need

            SPListItemCollection items = li.GetItems(q);

            foreach (SPListItem item in items)
            {
               

                string ResultItemTitle = item["jokename1"].ToString();

                if (ResultItemTitle == "123 testing")

                 
                    Txttodayjoke1.TextMode = TextBoxMode.MultiLine;
                    Txttodayjoke1.Text = ResultItemTitle;
             
                }
}
             
            }

Thursday 6 March 2014

Fusion Chart in Sharepoint

Pravin Pawar: Fusion Chart in Sharepoint: Walkthrough: Creating a Basic SharePoint Fusion Chart Web Part and its features (Note: Before Starting Application Download the following f...

Sunday 2 March 2014

Sorting asp.net GridView with SPDataSource

http://stackoverflow.com/questions/16027310/sorting-asp-net-gridview-with-spdatasource



Then I created my grid, based on the datasource
    <asp:GridView Visible="true" Width="100%"
                ID="gvInventar"
                AutoGenerateColumns="false" runat="server" CellPadding="2" AllowPaging="false" AllowSorting="true" OnSorted="gvInventar_Sorted" OnSorting="gvInventar_Sorting" GridLines="None" DataSourceID="SPdsInventarGrid" OnRowCommand="gvInventar_RowCommand">
                <Columns>
                    <asp:CommandField ButtonType="Image" ShowEditButton="true" EditImageUrl="/_layouts/images/edit.gif" UpdateImageUrl="/_layouts/images/save.gif" CancelImageUrl="/_layouts/images/delete.gif" />

                    <asp:TemplateField HeaderText="ID">
                        <ItemTemplate>
                            <asp:Label Text='<%# Bind("ID") %>' runat="server" ID="lblIdProduct"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Title" >
                        <ItemTemplate>
                            <asp:Label Text='<%# Bind("Title") %>' runat="server" ID="lblTitleProduct" ></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Product" SortExpression="Product">
                        <ItemTemplate>
                            <asp:Label Text='<%# Bind("EBS_x002e_CN_x002e_Inventar_x0028") %>' runat="server" ID="lblProduct" "></asp:Label>
                        </ItemTemplate>

                </Columns>
    </asp:GridView>
Now, I have this function where I wanted to get the current Query as a string and add <OrderBy>(my field) before <Query> but i get an error saying that the DataSource has been already declared (which is true because i want to be declared in asp)



protected void gvInventar_Sorting(object sender, GridViewSortEventArgs e)
    {
        SPQuery q = new SPQuery();
        q.Query = SPdsInventarGrid.SelectCommand;
        switch (e.SortExpression)
        {
            case "Product":
                if (e.SortDirection == SortDirection.Ascending)
                {
                    gvInventar.DataSource = q.Query;
                    gvInventar.DataBind();
                }
                else
                {
                }
               break;
        }
    }


<Columns>
    <asp:TemplateField HeaderText="ID" SortExpression="ID">
        <ItemTemplate>
            <asp:Label Text='<%# Bind("ID") %>' runat="server" ID="lblIdProduct" />
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Title" SortExpression="Title">
        <ItemTemplate>
            <asp:Label Text='<%# Bind("Title") %>' runat="server" ID="lblTitleProduct" />
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Product" SortExpression="EBS_x002e_CN_x002e_Inventar_x0028">
        <ItemTemplate>
            <asp:Label Text='<%# Bind("EBS_x002e_CN_x002e_Inventar_x0028") %>' runat="server"
                ID="lblProduct" />
        </ItemTemplate>
    </asp:TemplateField>
</Columns>
Now you can sort on all 3 columns:
enter image description here