Saturday, 7 June 2014

Display particular value and dropdwon filtering

SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite objSite = new SPSite(SPContext.Current.Web.Url))
                    {
                        using (SPWeb objWeb = objSite.OpenWeb())
                        {
                            SPList AppdetailsList = objWeb.Lists.TryGetList("OppositionDetails");
                            if (AppdetailsList != null)
                            {
                                SPQuery ListDataQuery = new SPQuery();

                                //ListDataQuery.Query = "<Where><And><Contains><FieldRef Name='IPR'/><Value Type='Text'>" + ddlIPR.SelectedValue.ToString() + "</Value></Contains><Or></Contains></Or></And></Where><OrderBy><FieldRef Name='Modified' Ascending='FALSE' /></OrderBy>";
                                ListDataQuery.Query = "<Where><Eq><FieldRef Name='IPR' /> <Value Type='Text'>" + ddlIPR.SelectedValue.ToString() + "</Value></Eq></Where>";

                                //ListDataQuery.Query = "<Where><And><Contains><FieldRef Name='IPR'/><Value Type='Text'>" + ddlIPR.SelectedValue.ToString() + "</Value></Contains><Or><Contains><FieldRef Name='Domain' /><Value Type='Text'>" + ddlDomain.SelectedValue.ToString() + "</Value></Contains><Contains><FieldRef Name='Products' /><Value Type='Text'>" + ddlProduct.SelectedValue.ToString() + "</Value></Contains></Or></And></Where><OrderBy><FieldRef Name='Modified' Ascending='FALSE' /></OrderBy>";
                                SPListItemCollection myColl = AppdetailsList.GetItems(ListDataQuery);

                             
            DataTable table;
            table = new DataTable();
            table.Columns.Add("OppNo", typeof(string));
            table.Columns.Add("OIPR", typeof(string));
                  table.Columns.Add("ODomain", typeof(string));
            table.Columns.Add("OCountry", typeof(string));
                  table.Columns.Add("OProducts", typeof(string));
            table.Columns.Add("OPPStatus", typeof(string));
               

            // Create rows for each splistitem
            DataRow row;
            foreach (SPListItem item in myColl)
            {
                row = table.Rows.Add();
                //row["Title"] = result.Name;
                row["OppNo"] = item["OppositionNo"];
                row["OIPR"] = item["IPR"];
                row["ODomain"] = item["Domain"];
                row["OCountry"] = item["Countries"];
                row["OProducts"] = item["Products"];
                row["OPPStatus"] = item["Status"];
               
             
              //  row["URL"] = "Your site url" + result.Url; //here need to append the site url to the item url
            }
            GrdOpposition.DataSource = table.DefaultView;
            GrdOpposition.DataBind();
        }

Friday, 6 June 2014

Griview , Datatable , Datarow Display splist data in gridview.

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
             <asp:GridView ID="GrdOpposition" runat="server" AutoGenerateColumns="false" GridLines="None"
                    CssClass="OrgGridView" PagerStyle-CssClass="OrgPagining" AlternatingRowStyle-CssClass="OrgAltRow"
                    AllowPaging="true" PageSize="20"
                   
                    onpageindexchanging="GrdOpposition_PageIndexChanging"
                    >
                    <Columns>
<asp:TemplateField HeaderText="Opposition No">
                            <ItemTemplate>
                                <asp:HyperLink ID="hlinkAppNoOp" runat="server" Text='<%# Eval("OppNo") %>' ForeColor="Red"></asp:HyperLink>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="IPR">
                            <ItemTemplate>
                                <asp:Label ID="grdlblIPROp" runat="server" Text='<%# Eval("OIPR") %>' ForeColor="Red"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Domain">
                            <ItemTemplate>
                                <asp:Label ID="OpgrdlblDomainOp" runat="server" Text='<%# Eval("ODomain") %>' ForeColor="Red"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Country">
                            <ItemTemplate>
                                <asp:Label ID="grdlblCountryOp" runat="server" Text='<%# Eval("OCountry") %>' ForeColor="Red"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Product">
                            <ItemTemplate>
                                <asp:Label ID="grdlblProdOp" runat="server" Text='<%# Eval("OProducts") %>' ForeColor="Red"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Status">
                            <ItemTemplate>
                                <asp:Label ID="grdlblStatusOp" runat="server" Text='<%# Eval("OPPStatus") %>' ForeColor="Red"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
</Columns>
                    <EmptyDataTemplate>
                        No Records Found
                    </EmptyDataTemplate>
                </asp:GridView>
                </ContentTemplate>
                </asp:UpdatePanel>




protected void btnSearch_Click(object sender, EventArgs e)
        {
            try
         
           
                {
           
                    GetTMApplicationNos2();
                }
            }
            catch (Exception ex)
            {
                //ACVT.SP.Core.ULSLogger.LogTrace(ex.Message, "btnSearch Click of IPR Home");
            }

        }





 public void GetTMApplicationNos2()
        {
            try
            {
                SPWeb mySite = SPContext.Current.Web;
            SPList myList = mySite.Lists["OppositionDetails"];
            SPListItemCollection items = myList.Items;
            //Here we will make a datatable and we will put our document library data to the data table
            DataTable table;
            table = new DataTable();
            table.Columns.Add("OppNo", typeof(string));
            table.Columns.Add("OIPR", typeof(string));
                  table.Columns.Add("ODomain", typeof(string));
            table.Columns.Add("OCountry", typeof(string));
                  table.Columns.Add("OProducts", typeof(string));
            table.Columns.Add("OPPStatus", typeof(string));
               

            // Create rows for each splistitem
            DataRow row;
            foreach (SPListItem item in items)
            {
                row = table.Rows.Add();
                //row["Title"] = result.Name;
                row["OppNo"] = item["OppositionNo"];
                row["OIPR"] = item["IPR"];
                row["ODomain"] = item["Domain"];
                row["OCountry"] = item["Countries"];
                row["OProducts"] = item["Products"];
                row["OPPStatus"] = item["Status"];
             
           
              //  row["URL"] = "Your site url" + result.Url; //here need to append the site url to the item url
            }
            GrdOpposition.DataSource = table.DefaultView;
            GrdOpposition.DataBind();
        }