Wednesday, May 12, 2010

How to Filter Data in gridview Depending upon selection of dropdown box

I have three drop down box like ProjName,CustName and SOOwner
step 1: First Check condition for All three Drop Down

tempdt = (DataTable) ViewState["DataTable"]; // tempdt is datatable
finaldt = tempdt.Clone(); // finaldt is datatable
string ProjName = null;
string CustName = null;
string SOOwner = null;
ProjName = ddlProjName.SelectedValue;
CustName = ddlCustName.SelectedValue;
SOOwner = ddlSOOwner.SelectedValue;
if (ProjName != "" && CustName != "" && SOOwner != "")
{
string query = "ProjectName='" + ProjName + "'and SO_Owner='" + SOOwner + "' and CustomerName='" + CustName + "'";
DataRow[] row = tempdt.Select(query);
for (int i = 0; i <= row.GetUpperBound(0); i++)
{
finaldt.ImportRow(row[i]);
}
}
else if (ProjName != "" && CustName != "")
{
string query = "ProjectName='" + ProjName + "'and CustomerName='" + CustName + "'";
DataRow[] row = tempdt.Select(query);
for (int i = 0; i <= row.GetUpperBound(0); i++)
{
finaldt.ImportRow(row[i]);
}
}
else if (CustName != "" && SOOwner != "")
{
string query = "CustomerName='" + CustName + "'and SO_Owner='" + SOOwner + "'";
DataRow[] row = tempdt.Select(query);
for (int i = 0; i <= row.GetUpperBound(0); i++)
{
finaldt.ImportRow(row[i]);
}
}
else if (ProjName != "" && SOOwner != "")
{
string query = "ProjectName='" + ProjName + "'and SO_Owner='" + SOOwner + "'";
DataRow[] row = tempdt.Select(query);
for (int i = 0; i <= row.GetUpperBound(0); i++)
{
finaldt.ImportRow(row[i]);
}
}
else if (ProjName != "")
{
string query = "ProjectName='" + ProjName + "'";
DataRow[] row = tempdt.Select(query);
for (int i = 0; i <= row.GetUpperBound(0); i++)
{
finaldt.ImportRow(row[i]);
}
}
else if (CustName != "")
{
string query = "CustomerName='" + CustName + "'";
DataRow[] row = tempdt.Select(query);
for (int i = 0; i <= row.GetUpperBound(0); i++)
{
finaldt.ImportRow(row[i]);
}
}
else if (SOOwner != "")
{
string query = "SO_Owner='" + SOOwner + "'";
DataRow[] row = tempdt.Select(query);
for (int i = 0; i <= row.GetUpperBound(0); i++)
{
finaldt.ImportRow(row[i]);
}
}
this.ViewState["filterDt"] = finaldt;
gv1.Visible = true;
//gv1.DataSource = finaldt;
gv1.DataSource = finaldt;
gv1.DataBind();
}

How To Display Text Or LanId Into People Picker Control

Hi Guys

Now I am Explaining How To Display LanId Into peopleEntity Control at a time of Page Load

Steps :

Create PickerEntity object and assign user name to key propertie of PickerEntity :


PickerEntity entity = new PickerEntity();
entity.Key = user.LoginName;



Also Create ArrayList For updating PeopleEntity Like this:


ArrayList entityArrayList = new ArrayList();
entityArrayList.Add(entity);
pd1.UpdateEntities(entityArrayList);

Like This O/p U can See

Wednesday, May 5, 2010

How to access control from another user control in Asp.Net page

Hi ,
Create new website and add two .ascx pages .
Write coding for both user control and drag that user controls on default page.

Enter Below Code into ControlA.ascx page in source mode::

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ControlA.ascx.cs" Inherits="ControlA" %>





Enter Below Code into ControlA.ascx.cs file
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class ControlA : System.Web.UI.UserControl
{
string settext;
public string text
{
//get
//{
// return TextBox1.Text;
//}
set
{
TextBox1.Text = value;
}
}

protected void Page_Load(object sender, EventArgs e)
{

}
}

Create second User Control add button control to it::

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ControlB.ascx.cs" Inherits="ControlB" %>
<%@ Reference VirtualPath="~/ControlA.ascx" %>





After Click on Button call page.findcontrol method & get respected output::


public partial class ControlB : System.Web.UI.UserControl

{
protected void Page_Load(object sender, EventArgs e) {
}
protected void Button1_Click(object sender, EventArgs e) {
ControlA FirstUserControl = (ControlA)Page.FindControl("ControlA1");
FirstUserControl.text = "Hi";
}}

And The two control are communicating with each other