Click here to Skip to main content
15,887,676 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionHow to generate Licence Key for windows application ? Pin
imtiyajali29-Oct-14 21:32
imtiyajali29-Oct-14 21:32 
AnswerRe: How to generate Licence Key for windows application ? Pin
Garth J Lancaster29-Oct-14 21:40
professionalGarth J Lancaster29-Oct-14 21:40 
QuestionRegarding machine Round question on Ado.net Pin
Member 1116162529-Oct-14 4:03
Member 1116162529-Oct-14 4:03 
GeneralRe: Regarding machine Round question on Ado.net Pin
PIEBALDconsult29-Oct-14 4:19
mvePIEBALDconsult29-Oct-14 4:19 
AnswerRe: Regarding machine Round question on Ado.net Pin
Richard MacCutchan29-Oct-14 5:51
mveRichard MacCutchan29-Oct-14 5:51 
QuestionGridview in asp.net Pin
Member 1116162517-Oct-14 6:50
Member 1116162517-Oct-14 6:50 
AnswerRe: Gridview in asp.net Pin
Eddy Vluggen17-Oct-14 7:40
professionalEddy Vluggen17-Oct-14 7:40 
GeneralRe: Gridview in asp.net Pin
Member 1116162517-Oct-14 17:55
Member 1116162517-Oct-14 17:55 
HI,
This is my code but this code is not working,that means it
not displaying data from tables in Grid view.

Default.cs

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 System.Data.SqlClient;
using System.Drawing;


public partial class _Default : System.Web.UI.Page
{
String a, b;


protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{

bindGrid();

}
SqlConnection con = new SqlConnection(Class1.Con_String);
con.Open();
SqlCommand cmd = new SqlCommand("Select Department_ID,Department from Department_Master", con);
SqlDataReader dr = cmd.ExecuteReader();
ddldept.DataSource = dr;
ddldept.DataBind();
con.Close();
bindGrid();
}
void bindGrid()
{

SqlConnection con1 = new SqlConnection(Class1.Con_String);
con1.Open();
SqlCommand cmd1 = new SqlCommand("Select Designation_ID,Designation from Designation_Master", con1);
SqlDataReader dr1 = cmd1.ExecuteReader();
ddldesg.DataBind();
con1.Close();

SqlConnection con11 = new SqlConnection(Class1.Con_String);
con11.Open();
String cmd11 = "Select Employee_Master.Emp_ID,Employee_Master.Emp_Name,Employee_Master.Email_ID,Employee_Master.Salary,Employee_Master.Photo,Department_Master.Department,Designation_Master.Designation,Employee_Master.Department_ID,Employee_Master.Designation_ID from Employee_Master Inner Join Department_Master on Employee_Master.Department_ID=Department_Master.DEpartment_ID Inner Join Designation_Master on Employee_Master.Desgination_ID=Designation_Master.Designation_ID";
bool whereadded=false;
if(ddldept.SelectedIndex>0)
{
cmd11 += "where Department_Master.Department_ID="+ ddldept.SelectedValue;
GridView1.EditIndex = -1;
whereadded = true;
}
if (ddldesg.SelectedIndex > 0)
{
if (whereadded == true)
{
GridView1.EditIndex = -1;
cmd11 += "and Designation_Master.Designation_ID=" + ddldesg.SelectedValue;
}

}
if (ViewState["sort"] != null)
{
cmd11 += "order by"+ ViewState["sort"];
GridView1.EditIndex = -1;
}
SqlDataAdapter da = new SqlDataAdapter(cmd11,con11);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
con11.Close();
}

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
ViewState["sort"] = e.SortExpression;
bindGrid();
}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.EditIndex = -1;
GridView1.SelectedIndex = -1;
GridView1.PageIndex = e.NewPageIndex;
bindGrid();
}

protected void ddldept_SelectedIndexChanged(object sender, EventArgs e)
{
bindGrid();
}
protected void ddldesg_SelectedIndexChanged(object sender, EventArgs e)
{
bindGrid();
}



protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
a=GridView1.DataKeys[e.NewEditIndex].Values[1].ToString();
b=GridView1.DataKeys[e.NewEditIndex].Values[2].ToString();
GridView1.EditIndex = e.NewEditIndex;
bindGrid();
SqlConnection con = new SqlConnection(Class1.Con_String);
con.Open();
SqlCommand cmd1 = new SqlCommand("Select Designation_ID,Designation from Designation_Master",con);
SqlDataReader dr1 = cmd1.ExecuteReader();
DropDownList ddl2=((DropDownList)GridView1.Rows[e.NewEditIndex].Cells[6].FindControl("ddl2"));
ddl2.DataSource = dr1;
ddl2.DataBind();
ddl2.SelectedValue = b;
con.Close();
SqlConnection conn = new SqlConnection(Class1.Con_String);
conn.Open();
SqlCommand cmd2 = new SqlCommand("Select Department_ID,Department from Department_Master",conn);
SqlDataReader dr2 = cmd2.ExecuteReader();
DropDownList ddl1=((DropDownList)GridView1.Rows[e.NewEditIndex].Cells[5].FindControl("ddl1"));
ddl1.DataBind();
ddl1.SelectedValue = a;
conn.Close();
}

protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
bindGrid();
}

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
decimal salary=(decimal)DataBinder.Eval(e.Row.DataItem,"Salary");
if ((salary > 50000) && (salary < 75000))
{
e.Row.ForeColor = Color.Red;
}
else
{
e.Row.ForeColor = Color.Green;
}
}
}

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
String id = GridView1.DataKeys[e.RowIndex].Value.ToString();
String name = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].FindControl("txtname")).Text;
String email=((TextBox)GridView1.Rows[e.RowIndex].Cells[2].FindControl("txtemail")).Text;
String salary=((TextBox)GridView1.Rows[e.RowIndex].Cells[3].FindControl("txtsalary")).Text;
FileUpload photo=((FileUpload)GridView1.Rows[e.RowIndex].Cells[4].FindControl("fuphoto"));
String desgname=((DropDownList)GridView1.Rows[e.RowIndex].Cells[6].FindControl("ddl2")).SelectedValue;
String departname=((DropDownList)GridView1.Rows[e.RowIndex].Cells[5].FindControl("ddl1")).SelectedValue;
SqlConnection con = new SqlConnection(Class1.Con_String);
con.Open();
if (photo.HasFile)
{
SqlCommand cmd = new SqlCommand("Update Employee_Master Set Employee_Master.Emp_Name=@name,Employee_Master.Email_ID=@email,Employee_Master.Salary=@salary,Employee_Master.Photo=@photo,Employee_Master.Department_ID=@departname,Employee_Master.Designation_ID=@desgname where Employee_Master.Emp_ID="+id,con);
cmd.Parameters.AddWithValue("@name",name);
cmd.Parameters.AddWithValue("@email",email);
cmd.Parameters.AddWithValue("@salary",salary);
cmd.Parameters.AddWithValue("@ photo",photo);
cmd.Parameters.AddWithValue("@desgname",desgname);
cmd.Parameters.AddWithValue("@departname",departname);
}
SqlCommand cmd1 = new SqlCommand("Update Employee_Master Set Employee_Master.Emp_Name=@name,Employee_Master.Email_ID=@email,Employee_Master.Salary=@salary,Employee_Master.Department_ID=@departname,Employee_Master.Designation_ID=@desgname where Employee_Master.Emp_ID="+ id,con);
cmd1.Parameters.AddWithValue("@name",name);
cmd1.Parameters.AddWithValue("@email",email);
cmd1.Parameters.AddWithValue("@salary",salary);
cmd1.Parameters.AddWithValue("@desgname",desgname);
cmd1.Parameters.AddWithValue("@departname",departname);
cmd1.ExecuteNonQuery();
GridView1.EditIndex = -1;
con.Close();
bindGrid();
}





===========================================================================================================

Default2.cs



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 System.Data.SqlClient;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String id=Request.QueryString["Emp_ID"];
if (id == null)
{
Response.Redirect("Default.aspx");
return;
}
SqlConnection con = new SqlConnection(Class1.Con_String);
con.Open();
SqlCommand cmd = new SqlCommand("Select Employee_Master.Emp_ID,Employee_Master.Emp_Name,Employee_Master.Email_ID,Employee_Master.Salary,Employee_Master.Photo,Employee_Master.Department_ID,Employee_master.Designation_ID, Department_Master.Department_ID,Designation_Master.Designation_ID from Employee_Master Inner Join Department_Master on Employee_Master.Department_ID=Designation_Master.Desgination_ID",con);
SqlDataReader dr = cmd.ExecuteReader();
DetailsView1.DataSource = dr;
DetailsView1.DataBind();
con.Close();
}
}
GeneralRe: Gridview in asp.net Pin
Eddy Vluggen19-Oct-14 3:22
professionalEddy Vluggen19-Oct-14 3:22 
SuggestionRe: Gridview in asp.net Pin
Richard Deeming20-Oct-14 1:42
mveRichard Deeming20-Oct-14 1:42 
GeneralRe: Gridview in asp.net Pin
vishal gawai14-Nov-14 4:27
vishal gawai14-Nov-14 4:27 
QuestionIP CAM WITH VB.NET Pin
ssc.noman13-Oct-14 21:30
ssc.noman13-Oct-14 21:30 
SuggestionRe: IP CAM WITH VB.NET Pin
Richard MacCutchan14-Oct-14 4:58
mveRichard MacCutchan14-Oct-14 4:58 
QuestionConverting Excel application into a Web Service Pin
Sujana Alluru13-Oct-14 2:56
professionalSujana Alluru13-Oct-14 2:56 
AnswerRe: Converting Excel application into a Web Service Pin
ZurdoDev13-Oct-14 3:28
professionalZurdoDev13-Oct-14 3:28 
GeneralRe: Converting Excel application into a Web Service Pin
Sujana Alluru13-Oct-14 4:08
professionalSujana Alluru13-Oct-14 4:08 
AnswerRe: Converting Excel application into a Web Service Pin
ZurdoDev13-Oct-14 4:09
professionalZurdoDev13-Oct-14 4:09 
GeneralRe: Converting Excel application into a Web Service Pin
Eddy Vluggen13-Oct-14 8:26
professionalEddy Vluggen13-Oct-14 8:26 
AnswerRe: Converting Excel application into a Web Service Pin
Gerry Schmitz13-Oct-14 11:14
mveGerry Schmitz13-Oct-14 11:14 
GeneralRe: Converting Excel application into a Web Service Pin
Sujana Alluru13-Oct-14 21:09
professionalSujana Alluru13-Oct-14 21:09 
GeneralRe: Converting Excel application into a Web Service Pin
Gerry Schmitz13-Oct-14 21:49
mveGerry Schmitz13-Oct-14 21:49 
GeneralRe: Converting Excel application into a Web Service Pin
Sujana Alluru14-Oct-14 0:10
professionalSujana Alluru14-Oct-14 0:10 
GeneralRe: Converting Excel application into a Web Service Pin
Gerry Schmitz14-Oct-14 11:29
mveGerry Schmitz14-Oct-14 11:29 
AnswerRe: Converting Excel application into a Web Service Pin
Pete O'Hanlon13-Oct-14 21:21
mvePete O'Hanlon13-Oct-14 21:21 
GeneralRe: Converting Excel application into a Web Service Pin
Sujana Alluru14-Oct-14 19:56
professionalSujana Alluru14-Oct-14 19:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.