using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Init(object sender, EventArgs e)
    {
        
        listFormUser.Items.Add(new ListItem("----Все----","-1"));
        listToUser.Items.Add(new ListItem("----Все----", "-1"));
        listUser.Items.Add(new ListItem("----Все----", "-1"));
        SqlCommand comm = new SqlCommand("SELECT userid,useruri FROM dbo.users", new SqlConnection(SqlDataSource1.ConnectionString));
        
        try
        {
            comm.CommandType = CommandType.Text;
            comm.Connection.Open();
            SqlDataReader read = comm.ExecuteReader();
            while (read.Read())
            {
               // ListItem item = new ListItem(Convert.ToString(read[1]), Convert.ToString(read[0]));
                listFormUser.Items.Add(new ListItem(Convert.ToString(read[1]), Convert.ToString(read[0])));
                listToUser.Items.Add(new ListItem(Convert.ToString(read[1]), Convert.ToString(read[0])));
                listUser.Items.Add(new ListItem(Convert.ToString(read[1]), Convert.ToString(read[0])));
            }
        }
        catch
        { }
        finally
        {
            comm.Connection.Close();
        }

    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void GridView1_DataBinding(object sender, EventArgs e)
    {
        
    }
    protected void GridView1_DataBound(object sender, EventArgs e)
    {
        
    }
    protected void listFormUser_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (listFormUser.SelectedItem.Text != "----Все----")
            Session["curuser"] = "from_field='" + listFormUser.SelectedItem.Text + "'";
        else
            Session["curuser"] =  "";
    }
    protected void listToUser_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (listToUser.SelectedItem.Text != "----Все----")
            Session["curuser"] =  "to_field='" + listToUser.SelectedItem.Text + "'";
        else
            Session["curuser"] = "";
    }
    protected void listUser_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (listUser.SelectedItem.Text != "----Все----")
            Session["curuser"] = "to_field='" + listUser.SelectedItem.Text + "' OR from_field='" + listUser.SelectedItem.Text + "'";
        else
            Session["curuser"] = "";
    }
    protected void butShowAll_Click(object sender, EventArgs e)
    {
        GridView1.AllowPaging = !GridView1.AllowPaging;
        if (GridView1.AllowPaging)
            butShowAll.Text = "Показать всё";
        else
            butShowAll.Text = "Показать постранично";
    }
}
