Monday 28 May 2012

Amount (Point) Added in the Gridview & DataList:


Amount (Point) Added in the Gridview & DataList:

    <asp:BoundField HeaderText="Unit Price"
     DataField="UnitPrice" SortExpression="UnitPrice  DataFormatString="{0:c}">
      <ItemStyle HorizontalAlign="Right"></ItemStyle>        </asp:BoundField>

Datalist :
<%#String.Format("{0:c}", (DataBinder.Eval(Container.DataItem, "totalprice")))%>

Null Date Field Assigned NA in DataLst




C#:
dob:
<asp:Label ID="dobLabel" runat="server" Text='<%# Eval("dob")==DBNull.Value ? "N/A": Eval("dob","{0:d}") %>'></asp:Label>

<asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "dob")==DBNull.Value ? "N/A": DataBinder.Eval(Container.DataItem, "dob","{0:d}") %>'></asp:Label><br />

VB.NET:
dob:
<asp:Label ID="dobLabel" runat="server" Text='<%# IIF(Eval("dob") IS DBNull.Value,"N/A", Eval("dob","{0:d}")) %>'></asp:Label>

or

<asp:Label ID="Label3" runat="server" Text='<%# IIF(DataBinder.Eval(Container.DataItem, "dob") IS DBNull.Value, "N/A", DataBinder.Eval(Container.DataItem, "dob","{0:d}")) %>'></asp:Label><br />

C#

<%# DataBinder.Eval(Container.DataItem, "RecentDate") == "{1/1/0001 12:00:00 AM}" ? "n/a" : DataBinder.Eval(Container.DataItem, "RecentDate", "{0:d}")%>
Text='<%# Eval("RecentDate") == DBNull.Value ? "n/a": Eval("RecentDate","{0:d}") %>'
Text='<%# Convert.ToString(Eval("myDatetime")) =="1/1/0001 12:00:00 AM" ? "N/A" : Eval("myDatetime", "{0:d}")%>'

Tender show Three Days :


SqlDataAdapter da5 = new SqlDataAdapter("select * from idco_tender where sale_date > getdate() and sale_date < DATEADD(day, 3, sale_date) ", con);
        DataSet dt5 = new DataSet();
        da5.Fill(dt5);
            if (dt5.Tables[0].Rows.Count > 0)
            {
                GridView3.Visible = true;
                Label1.Visible = false;
                GridView3.DataSource = dt5;
                GridView3.DataBind();
            }
          else
            {
                Label1.Visible = true;
                GridView3.Visible = false;
                Label1.Text = "Active Tender not Found";
            }

Popup


Freez Pane in Dynamic Table


Gridview Count INput




<asp:TemplateField HeaderText="Organization">
                       <ItemTemplate>
                           <asp:Label ID="Label1" runat="server" Text='<%#GetORGName(Convert.ToString(DataBinder.Eval(Container.DataItem, "org_id", ""))) %>'></asp:Label>
                       </ItemTemplate>
                   </asp:TemplateField>

public String GetORGName(string org_id)
   {
       if (org_id == null || org_id == "")
       {
           return "No Organization";
       }
       else
       {
           int org = Convert.ToInt32(org_id);
           string sql = "SELECT * FROM p2p_v2_registration WHERE org_id=" + org + "";
           SqlDataAdapter ad = new SqlDataAdapter(sql, con);
           DataTable dt = new DataTable();
           ad.Fill(dt);

           return dt.Rows[0]["organization"].ToString().Trim();
       }

Gridview LinkButton


Gridview LinkButton  


     <asp:TemplateField HeaderText="Order ID">
<ItemTemplate>
<asp:LinkButton ID="lnk_orderid" runat="server" ForeColor="Blue"
CommandArgument='<%#Eval("compl_id") %>'
Text='<%#Eval("compl_id") %>' Font-Bold="False" onclick="lnk_orderid_Click"
></asp:LinkButton>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>


div_compdetails.Visible =true;LinkButton lnk = (LinkButton)sender; string comp_code = lnk.CommandArgument.ToString();

Gridview Word Wrap


  

<asp:TemplateField HeaderText="EmailID" >
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("emailid") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label6" runat="server" Width="100px" Text='<%# Bind("emailid") %>' Style="word-break: break-all"></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>

Collapsible Data in GridView

Collapsible Data in GridView in order report page on Raasa.


 <asp:GridView ID="gvItems" runat="server" BackColor="White" BorderColor="#DEDFDE"
                        BorderStyle="Solid" BorderWidth="1px" CellPadding="4" ForeColor="Black"
                        GridLines="Vertical" PageSize="1"  AutoGenerateColumns="False" style="width:650px">
                       <HeaderStyle BackColor="#3b6c01" Font-Bold="True" Font-Size="14px" ForeColor="#ffffff" Height="35px" />
                       <RowStyle BackColor="White" ForeColor="#333333" />        
                       <AlternatingRowStyle BackColor="#F2F2F2" ForeColor="#333333" />
                       <PagerSettings Position="Top" />
                       <PagerStyle BackColor="#E4E4E4" ForeColor="#265CC0" Borderwidth="0px"/>  
                    <EmptyDataRowStyle ForeColor="#666666" Font-Bold="true" Font-Size="13px" HorizontalAlign="Center" />
                        <Columns>
                            <asp:TemplateField>
                                <HeaderTemplate>
                                    <table border="0" cellpadding="0" cellspacing="0" width="650px">
                                        <%--<tr><td colspan="5" align="left">Order Details</td></tr>--%>
                                        <tr>
                                            <td style="width:50px;text-align:center;"></td>
                                            <td style="width:150px;text-align:center;">Order No</td>
                                            <td style="width:200px;text-align:center;">Date</td>
                                            <td style="width:100px;text-align:center;">Items</td>
                                            <td style="width:150px;text-align:center;">Status</td>
                                        </tr>
                                    </table>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <table border="0" cellpadding="0" cellspacing="0" width="650px">
                                        <tr>
                                            <td style="width:50px;text-align:center;">
                                            <img id='toggle<%#Eval("id") %>' src="../web/images/plus.jpg" alt="Click here to see Order details" onclick='javascript:ToggleDisplay(<%# Eval("id") %>);' style="cursor:pointer;height:15px;width:15px" />    
                                            </td>        
                                            <td style="width:150px;text-align:center;">
                                            <p><asp:Label ID="lblorderid" runat="server" Text='<%# Eval("order_id")%>'></asp:Label></p>
                                            </td>
                                            <td style="width:200px;text-align:center;">
                                            <p><%# Eval("in_ts")%> </p>
                                            </td>
                                            <td style="width:100px;text-align:center;">
                                            <%# Eval("order_items")%>
                                            </td>
                                            <td style="width:150px;text-align:center;">
                                            <%# Eval("order_status")%>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>&nbsp;</td>
                                            <td colspan="4">
                                                <div id='coldiv<%# Eval("id") %>' style="display:none;width:600px;">
                                                    <asp:GridView ID="orderdetailsgrid" runat="server"  AutoGenerateColumns="False"
                                                        onrowdatabound="orderdetailsgrid_RowDataBound" ShowFooter="True"
                                                        Width="100%" >
                                                        <Columns>
                                                            <asp:BoundField DataField="prod_type" HeaderText="Type" HeaderStyle-Width="20%" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"/>
                                                            <asp:BoundField DataField="item_desc" HeaderText="Item Description" HeaderStyle-Width="32%" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"/>
                                                            <asp:BoundField DataField="price" HeaderText="Price" HeaderStyle-Width="10%" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"/>
                                                           
                                                            <asp:TemplateField HeaderText="Quantity" HeaderStyle-Width="20%" HeaderStyle-HorizontalAlign="Center">
                                                            <FooterStyle Font-Bold="true" Font-Size="13px" />
                                                                <FooterTemplate>Grand Total:</FooterTemplate>
                                                                <ItemTemplate>
                                                                    <asp:Label ID="lblqty" runat="server" Text='<%# Eval("qty") %>'></asp:Label>
                                                                </ItemTemplate>
                                                                <ItemStyle HorizontalAlign="Center" />
                                                                <FooterStyle HorizontalAlign="Right" />
                                                            </asp:TemplateField>

                                                            <asp:TemplateField HeaderText="Sub Total" HeaderStyle-Width="18%" HeaderStyle-HorizontalAlign="Center">
                                                                <ItemTemplate>
                                                                    <asp:Label ID="lblsubtot" runat="server" Text='<%# Eval("SubTotal") %>'></asp:Label>
                                                                </ItemTemplate>
                                                                <FooterTemplate>
                                                                    <asp:Label ID="lblgrandtotal" runat="server" Font-Bold="True" Font-Size="13px"></asp:Label>
                                                                </FooterTemplate>
                                                                <ItemStyle HorizontalAlign="Center" />
                                                                <FooterStyle HorizontalAlign="Center" />
                                                            </asp:TemplateField>                                      
                                                            </Columns>
                                                        <HeaderStyle BackColor="#999999" ForeColor="#ffffff" />
                                                    </asp:GridView>
                                                </div>
                                            </td>
                                        </tr>
                                    </table>
                                </ItemTemplate>
                            </asp:TemplateField>                                 
                        </Columns>
                        <EmptyDataTemplate>                           
                            <table border="0" cellpadding="0" cellspacing="0" width="650px">
                                <tr style="background-color:#3b6c01; color:#fff; font-family:Tahoma;font-size:14px;height:35px;">
                                    <td style="width:50px;text-align:center;"></td>
                                    <td style="width:150px;text-align:center;">Order No</td>
                                    <td style="width:200px;text-align:center;">Date</td>
                                    <td style="width:100px;text-align:center;">Items</td>
                                    <td style="width:150px;text-align:center;">Status</td>
                                </tr>
                                <tr><td colspan="5" align="center">&nbsp;</td></tr>
                                <tr><td colspan="5" align="center">No Records found.</td></tr>
                            </table>
                        </EmptyDataTemplate>
                </asp:GridView>


Step 2 :




using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Raasa_BusinessLogicLayer.CITSPL_logics;

namespace Raasa_PresentationLayer.admin
{
    public partial class order_rpt : System.Web.UI.Page
    {
        bl_raasa_admin obj = new bl_raasa_admin();
        decimal grandtotal;
        protected void Page_Load(object sender, EventArgs e)
        {
            if ((Convert.ToString(Session["user_id"]) == ""))
            {
                //Session.Clear();
                Response.Redirect("~/web/Login.aspx");
            }
            if (!IsPostBack)
            {
                obj.BindParentGrid_orderRpt(gvItems, txtorderno.Text.Trim(), ddlorderstatus.SelectedValue);
                obj.BindChildGrid(gvItems);
            }
        }

        protected void orderdetailsgrid_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                grandtotal += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "SubTotal"));

            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                Label lbl = (Label)e.Row.FindControl("lblgrandtotal");
                lbl.Text = grandtotal.ToString();
                grandtotal = 0;
            }
        }

        protected void btnsearch_Click(object sender, EventArgs e)
        {
            obj.BindParentGrid_orderRpt(gvItems, txtorderno.Text.Trim(), ddlorderstatus.SelectedValue);
            obj.BindChildGrid(gvItems);
        }
    }
}