Monday, 4 April 2016

Retrieve data from Mysql database into Grid view and also check the status from Grid view row cells based condition checking :

(Note : Each and every records having the separate track item values.You should to follow Create or Update date from step by step  as tracking  status ) 




Screen Shot 1: 


Screen Shot 2:

Screen Shot 3: 


Screen Shot 4:



Screen Shot 5:




Steps :

The "trackingmaterial.aspx" 
(select any one master page in own.)
I use visual studio 2010 to design the page.

Picture : 




Aspx Code :


<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="trackmaterial.aspx.cs" Inherits="trackmaterial" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .style1
        {
        }
    </style>
     <style type="text/css">
        :focus {
        background-color:white;

        }

    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<center>
<h3> MATERIAL TRACKING
</h3>
</center>
<br />

<center>
    <table style="height: 55px; width: 424px">
        <tr>
            <td class="style1">
                &nbsp;
                Enter Material Number</td>
            <td>
                <asp:TextBox ID="txtrack" runat="server" Height="25px" Width="134px"></asp:TextBox>
                &nbsp;
            </td>
            <td>
                <asp:Button ID="bnsearch" runat="server" Text="Search"  Height="30px" style="font-size: large"
                    onclick="bnsearch_Click" />
                &nbsp;
            </td>
        </tr>
        <tr>
            <td class="style1" colspan="3">
                &nbsp;
                &nbsp;
                &nbsp;
            </td>
        </tr>
        <tr>
            <td class="style1" colspan="3">
                &nbsp;
                 <asp:Label ID="lblstatus" runat="server" Text="Status :-" ForeColor="#FF3300"
                    style="text-align: left"></asp:Label>
                <asp:Label ID="lblmsg" runat="server"></asp:Label>
                &nbsp;
                &nbsp;
                         
            </td>
        </tr>
        <tr>
            <td class="style1">
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
</center>
<br />
<center>
    <asp:GridView ID="grvw" runat="server"  OnRowDataBound="grv_RowDataBound"
        >
    </asp:GridView>
</center>
<br />
<br />
</asp:Content>

C# Code :
(Rename it your lables , textboxs,buttons,gridviews)
Like Below:

label1=lblmsg,

label2=lblstatus,
Textbox=txttrack,
Gridview1=grvw,
Button=bnsearch.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MySql.Data.MySqlClient;
using System.Globalization;
using System.Configuration;
public partial class trackmaterial : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        lblmsg.Visible = false;
        lblstatus.Visible = false;
        txtrack.Focus();
    }
    protected void bnsearch_Click(object sender, EventArgs e)
    {

        string connString = ConfigurationManager.ConnectionStrings["constr1"].ConnectionString;
        MySqlConnection myConnection = new MySqlConnection(connString);
        myConnection.Open();
        MySqlCommand cmd = new MySqlCommand("select grnno 'Grn-No',DATE_FORMAT(grndate, '%d-%m-%Y') AS 'GRN-Date',deptname 'Department Name',upper(CONCAT_ws('',pmdetails,'/ ',pmmno,'/ ',pmsno))  'Problem Meterial Details',problem 'Problem',upper(CONCAT_ws('',rmdetails,'/ ',rmmno,'/ ',rmsno)) 'Stand By Meterial Details',staffname 'Staff Name' ,trackitem 'Track Item' from grntable where grnno='" + txtrack.Text + "'", myConnection);
        MySqlDataAdapter da = new MySqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        grvw.DataSource = ds;
        grvw.DataBind();
        myConnection.Close();

    }
    protected void grv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
//Row cell or colums value

                TableCell item = e.Row.Cells[7];
                if (item.Text == "GRC")
                {
                    lblstatus.Visible = true;
                    lblmsg.Visible = true;
                    lblmsg.Text = "Problem Material on Entry Process";
                }

                else if (item.Text == "DRS")
                {
                    lblstatus.Visible = true;
                    lblmsg.Visible = true;
                    lblmsg.Text = "Problem Material Received form Online System";

                }

                else if (item.Text == "GPS")
                {
                    lblstatus.Visible = true;
                    lblmsg.Visible = true;
                    lblmsg.Text = "Problem Material Under Repair from Online System ";
                }

                else if (item.Text == "GFS")
                {
                    lblstatus.Visible = true;
                    lblmsg.Visible = true;
                    lblmsg.Text = "Problem Solved in Online System Service Room  ";

                }
                else if (item.Text == "DSR")
                {
                    lblstatus.Visible = true;
                    lblmsg.Visible = true;
                    lblmsg.Text = "Problem Material Dispatched";

                }
                else if (item.Text == "GSC")
                {
                    lblstatus.Visible = true;
                    lblmsg.Visible = true;
                    lblmsg.Text = "Problem Material Sucessfully Deliverd ";
                }
                else
                {
                    lblstatus.Visible = true;
                    lblmsg.Visible = true;
                    lblmsg.Text = "No Material Number Found";
                }
            }
        }


    }
}


     
 








No comments:

Post a Comment

How to create a simple Hello World website in ASP.NET MVC using Razor Syntax: (Note: I am using Visual Studio 2012 ) Step 1: ...