数据绑定DropDownList过滤器 [英] Databound DropDownList Filter
本文介绍了数据绑定DropDownList过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个数据绑定到SqlDataSource的表单上有一个ddl。我试图过滤ddl只显示数据,具体取决于当前登录的用户。我将如何进行此操作?是否可以使用数据绑定ddl执行此操作?
使用系统;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Data;
使用 System.Data.SqlClient;
使用 System.Drawing;
使用 System.Text;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Configuration;
使用 System.Drawing.Printing;
public partial class FinancialProfileFormA:System.Web.UI.Page
{
protected void Page_Load( object sender,EventArgs e)
{
ButtonPrint.Attributes.Add( onclick, window .print();返回false);
}
受保护 void DropDownListSchool_SelectedIndexChanged1(< span class =code-keyword> object sender,EventArgs e)
{
SqlConnection con = new SqlConnection(System。 Configuration.ConfigurationManager.ConnectionStrings [ PasswordConnectionString]。ConnectionString);
con.Open();
SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings [ PasswordConnectionString]。ConnectionString);
con2.Open();
SqlCommand scmd = new SqlCommand( 从TableCOCINST中选择User_ID,其中User_ID = + DropDownListSchool.SelectedValue.ToString(),con);
SqlCommand scmd2 = new SqlCommand( 选择TableFIN2012中的User_ID,INSTRUCTIO,RESEARCH,PUBLIC_SER,ACADEMIC_S,STUDENT_SE,INSTITUTIO,PHYSICAL_P,SCHOLARSHI,AUXILIARY_,PHYSOS_PE,INDEXARSHI,AOTILIARY_,HOTPITALS,INDEPENDEN,OTHEREXP,TOTASSETS,TOTLIABILITY,NoNEXPPERMRESASSETS,UNRNETASSETS,TOTALREV,TUITFEES,CURRDEBT,LONGTERMDEBT其中User_ID = + DropDownListSchool.SelectedValue.ToString(),con2);
SqlDataReader dr = scmd.ExecuteReader();
SqlDataReader dr2 = scmd2.ExecuteReader();
if (dr.Read())
if (dr2.Read( ))
{
TextBoxLYInstr.Text = dr2 [ INSTRUCTIO跨度>]的ToString();
TextBoxLYRes.Text = dr2 [ RESEARCH]。ToString();
TextBoxLYPubS.Text = dr2 [ PUBLIC_SER]。ToString();
TextBoxLYAcad.Text = dr2 [ ACADEMIC_S]。ToString();
TextBoxLYStudS.Text = dr2 [ STUDENT_SE]。ToString();
TextBoxLYInstiS.Text = dr2 [ INSTITUTIO]。ToString();
TextBoxLYOperM.Text = dr2 [ PHYSICAL_P]。ToString();
TextBoxLYSFEDA.Text = dr2 [ SCHOLARSHI]。ToString();
TextBoxLYAuxE.Text = dr2 [ AUXILIARY _]。ToString();
TextBoxLYHosS.Text = dr2 [ HOSPITALS]。ToString();
TextBoxLYIndeO.Text = dr2 [ INDEPENDEN]。ToString();
TextBoxLYOED.Text = dr2 [ OTHEREXP]。ToString();
TextBoxLYTA.Text = dr2 [ TOTASSETS]。ToString();
TextBoxLYTL.Text = dr2 [ TOTLIABILITY]。ToString();
TextBoxLYNPRNA.Text = dr2 [ NoNEXPPERMRESASSETS]。ToString();
TextBoxLYTUNA.Text = dr2 [ UNRNETASSETS]。ToString();
TextBoxLYTR.Text = dr2 [ TOTALREV]。ToString();
TextBoxLYTFN.Text = dr2 [ TUITFEES]。ToString();
TextBoxLYCD.Text = dr2 [ CURRDEBT]。ToString();
TextBoxLYLTD.Text = dr2 [ LONGTERMDEBT]。ToString();
TextBoxINST_ID.Text = dr [ INST_ID]。ToString();
}
dr.Close();
con.Close();
dr2.Close();
con2.Close();
{
}
}
}
解决方案
< blockquote>这应该对你有所帮助。在会话中存储用户或通过参数获取用户。
http://stackoverflow.com/questions/9459118/save-the-user-name-in-session-from-the-login-page [ ^ ]
如果有帮助,请批准解决方案。
谢谢。
I have a ddl on a form that is databound to a SqlDataSource. I am trying to filter the ddl to only show data depending on the user that is currently logged in. How will I go by doing this? Is it possible to do this with a databound ddl?
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using System.Drawing.Printing;
public partial class FinancialProfileFormA : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ButtonPrint.Attributes.Add("onclick", "window.print(); return false");
}
protected void DropDownListSchool_SelectedIndexChanged1(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
con.Open();
SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
con2.Open();
SqlCommand scmd = new SqlCommand("Select User_ID from TableCOCINST where User_ID = " + DropDownListSchool.SelectedValue.ToString(), con);
SqlCommand scmd2 = new SqlCommand("Select User_ID, INSTRUCTIO, RESEARCH, PUBLIC_SER, ACADEMIC_S, STUDENT_SE, INSTITUTIO, PHYSICAL_P, SCHOLARSHI, AUXILIARY_, HOSPITALS, INDEPENDEN, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT from TableFIN2012 where User_ID = " + DropDownListSchool.SelectedValue.ToString(), con2);
SqlDataReader dr = scmd.ExecuteReader();
SqlDataReader dr2 = scmd2.ExecuteReader();
if (dr.Read())
if (dr2.Read())
{
TextBoxLYInstr.Text = dr2["INSTRUCTIO"].ToString();
TextBoxLYRes.Text = dr2["RESEARCH"].ToString();
TextBoxLYPubS.Text = dr2["PUBLIC_SER"].ToString();
TextBoxLYAcad.Text = dr2["ACADEMIC_S"].ToString();
TextBoxLYStudS.Text = dr2["STUDENT_SE"].ToString();
TextBoxLYInstiS.Text = dr2["INSTITUTIO"].ToString();
TextBoxLYOperM.Text = dr2["PHYSICAL_P"].ToString();
TextBoxLYSFEDA.Text = dr2["SCHOLARSHI"].ToString();
TextBoxLYAuxE.Text = dr2["AUXILIARY_"].ToString();
TextBoxLYHosS.Text = dr2["HOSPITALS"].ToString();
TextBoxLYIndeO.Text = dr2["INDEPENDEN"].ToString();
TextBoxLYOED.Text = dr2["OTHEREXP"].ToString();
TextBoxLYTA.Text = dr2["TOTASSETS"].ToString();
TextBoxLYTL.Text = dr2["TOTLIABILITY"].ToString();
TextBoxLYNPRNA.Text = dr2["NoNEXPPERMRESASSETS"].ToString();
TextBoxLYTUNA.Text = dr2["UNRNETASSETS"].ToString();
TextBoxLYTR.Text = dr2["TOTALREV"].ToString();
TextBoxLYTFN.Text = dr2["TUITFEES"].ToString();
TextBoxLYCD.Text = dr2["CURRDEBT"].ToString();
TextBoxLYLTD.Text = dr2["LONGTERMDEBT"].ToString();
TextBoxINST_ID.Text = dr["INST_ID"].ToString();
}
dr.Close();
con.Close();
dr2.Close();
con2.Close();
{
}
}
}
解决方案
This should help you. Storing User in Session or getting it by parameter.
http://stackoverflow.com/questions/9459118/save-the-user-name-in-session-from-the-login-page[^]
Please approve solution if it helps.
Thanks.
这篇关于数据绑定DropDownList过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文