- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我遇到的问题不是紧急情况,但我不知道该怎么做。我有两个 aspx 网络表单页面。每个都有一个下拉列表。两者都由来自 sql server 的相同数据源填充。问题是,如果我在第 1 页选择一个值,然后转到第 2 页,它会重新填充下拉列表(因为它是从数据源中填充的)。例如第2页下拉列表是Hamilton,然后点击第2页Hamilton需要显示。目前它将显示数据库中的第一条记录。这只是变得更加用户友好的功能,并不是什么大问题。我不知道真正在这个地方在哪里,所以我没有任何代码可以显示。这似乎是一个独特的问题,因为我找不到任何关于此的论坛。我不确定 jQuery 是否是执行此操作的有效方法。这是我在页面加载期间填充下拉列表的方式..
protected void Page_Load(object sender, EventArgs e) {
//Session["dship"] = ddlDealershipRec.SelectedIndex;
conn.Open();
//This selects the user's ID where the user name equals the user that is currently logged in.
SqlCommand cmdUserID = new SqlCommand("SELECT UserID from Users WHERE UserName = '" + User.Identity.Name + "'", conn);
selectUserID = Convert.ToString(cmdUserID.ExecuteScalar());
//Selections the location ID where the userID is equal the the UserName.
SqlCommand cmdLocationID = new SqlCommand("SELECT LocationID from UserControl WHERE UserID = '" + selectUserID + "'", conn);
selectLocationID = Convert.ToString(cmdLocationID.ExecuteScalar());
//Selects the Coporate or Store where the userID is equal to the UserName.
SqlCommand cmdCorporateStore = new SqlCommand("SELECT MAX(CorporateStore) from Users WHERE UserID = '" + selectUserID + "'", conn);
selectCorporateStore = Convert.ToString(cmdCorporateStore.ExecuteScalar());
//Selects if the user is an Admin.
SqlCommand cmdAdmin = new SqlCommand("SELECT MAX(Admin) from Users WHERE UserID = '" + selectUserID + "'", conn);
selectAdmin = Convert.ToString(cmdAdmin.ExecuteScalar());
conn.Close();
//use to display "Garage" when an admin logs in.
if (selectAdmin == "Yes")
{
Control allUsers = this.Page.Master.FindControl("login").FindControl("loginview").FindControl("ulmenu").FindControl("allUsers");
allUsers.Visible = true;
}
gvVehicleTEMP.ControlStyle.Font.Size = 8;
if (!IsPostBack)
{
ddlDealershipRec.Items.Clear();
List<int> locationIDList = new List<int>();
List<string> locationList = new List<string>();
conn.Open();
//used to populate the dropDownList depending who is logged in.
using (SqlDataReader reader = cmdLocationID.ExecuteReader())
{
while (reader.Read())
{
int locationID = reader.GetInt32(0);
locationIDList.Add(locationID);
}
conn.Close();
}
foreach (int id in locationIDList)
{
conn.Open();
SqlCommand cmdLocation = new SqlCommand("SELECT LocationName FROM Location WHERE LocationID = '" + id + "' ORDER BY LocationName ASC", conn);
using (SqlDataReader reader = cmdLocation.ExecuteReader())
{
while (reader.Read())
{
string location = reader.GetString(0);
locationList.Add(location);
}
conn.Close();
}
}
foreach (string location in locationList)
{
ddlDealershipRec.Items.Add(new ListItem(location));
}
}
}
提前致谢!
编辑:我已经从我的第一页添加了我的整个页面加载。如您所见,这里发生了很多事情,而且它疯狂地由数据库驱动。我不得不做一些与预期不同的事情,因为我在 Active Directory 中使用表单例份验证。 select cmdLocationID 用于从我的“UserControl”表中获取数据。该表只有两列,UserID 和 LocationID。由于我的 UserID 是 1,并且我拥有所有 7 或 8 家商店,因此有 7 或 8 个 UserID 为 1,并且它与商店相关。然后我将它保存到一个字符串并将它添加到位置列表基本上然后填充下拉列表。
最佳答案
从高层次的角度来看,您可以做的是将选择的唯一标识符(如 DropDownList 的 SelectedIndex)保存到用户状态,然后在其他页面加载时,将 DropDownList 与该唯一标识符匹配。
There are many ways to save information in user state .一种方式是在 session 状态中。以下是在 session 状态中保存信息的方法:
Session["VariableName"] = (int)ddlNameOfDropdownList.SelectedIndex;
然后您可以在另一个时间在另一个页面上访问该 Session 变量(默认情况下它们会在 20 分钟内超时,因此如果您的表单花费的时间比这更长,您可能需要使用 ViewState 之类的东西)。
要访问 session 变量并在另一个页面上使用它,您可以在 PageLoad 中添加:
ddlOtherDropdownList.SelectedIndex = Convert.ToInt32(Session["VariableName"]);
当您访问 session 变量时,我没有检查空值,但这些都是辅助问题。
编辑:添加了显式转换。
编辑:您可能希望将点击事件添加到第一页上的按钮,将您重定向到第二页,如下所示:
void btnToSecondPage_Click(Object sender, EventArgs e)
{
Session["dropdownSelected"] = (int)ddlDealershipRec.SelectedIndex;
Response.Redirect("SecondPage.aspx");
}
这会在转到下一页之前将所选索引保存为 session 变量。然后,在第二个页面加载时,在填充 ddlDealershipRec 之后,您会希望这样:
ddlDealershipRec.SelectedIndex = Convert.ToInt32(Session["dropdownSelected");
关于c# - 不同aspx页面上的下拉列表需要 "relate"互相,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18494071/
我知道,关系数据库是一种数据库,其中一个表中的字段链接到其他表中的行,就像这样。 但我不明白这对我作为网络开发人员意味着什么! 据我所知,具有联接和嵌套选择的查询会降低性能(尤其是具有数十个联接的 d
我正在逻辑层面上设计一个数据库,以便稍后将其传递给程序员来交付。我只是粗略地了解它们的工作原理,所以我很难简洁地表达我的问题。这是我的问题: 我有一个名为 MEANINGS 的表。 我有一个名为 WO
在 Jira 中,将项目链接在一起既简单又实用。 例如,您可以轻松克隆一个问题:创建问题 100,将其克隆到 101。100 然后显示“这个问题有一个克隆:101”,然后 101 显示“这个问题是一个
所以我有这些实体: Group { id: number; name: string; persons: Person[]; } Person { name: stri
我真不敢相信,经过 5 年的 Rails 编程,我还没有想出一个好的解决方案来解决这个常见问题。另外,我假设这个特定问题有 100 个答案,但我不知道定义(关系?协会?等)来很好地搜索它。所以我们开始
我想在我的数据库记录中包含动态字段。 例如:我想构建一个应用程序供用户创建自己的表单。 用户可以创建以下表单: 个人资料: 全名 街道 工作 电话 首页 工作 移动 兴趣 兴趣 1 兴趣 2 兴趣 3
共有三个表:businesses、categories、categorizations、 CREATE TABLE businesses ( id SERIAL PRIMARY KEY, na
这个问题在这里已经有了答案: How can I vertically center a div element for all browsers using CSS? (48 个答案) 关闭 6
对于问题的错误措辞,我们深表歉意。我是 stackoverflow 的新手,也是 PIG 的新手,正在尝试自己进行实验。 我有一个处理 words.t 文件和 data.txt 文件的场景。 文字.t
关于像Cassandra 这样的反革命NoSQL 数据库的讨论很多。 , CouchDB , Hypertable , MongoDB , Project Voldemort , BigTable ,
我的处境与ICTylor's post here 类似。 . 所以我有: user1=User.find(1); user2=User.find(2); written=Micropost.where
尝试获取与事件关联的用户列表。这是我 Eloquent 模型: 用户.php: public function fbevents() { $this->belongsToMany('Fbeve
我有一个在 MySQL 数据库上运行的 Web 应用程序(正在开发中)。我正在考虑将我的应用程序迁移到 Google App Engine,并希望更好地了解如何将我的简单关系数据库模型转换为非关系方法
我应该在构造函数中放入什么:与实例相关的东西还是与类相关的东西? 考虑这段代码: var count = 0 TView = function (x, y) { this.x = x, this.y
我正在努力使用 postgreSQL,因为我不知道如何将 A 类型的一个实例链接到 B 类型的一组实例。我将举一个简短的例子: 假设我们要建立一个包含音乐专辑和人物的数据库,每个人都有一个他们最喜欢的
我需要检索一个对象并获取关系和嵌套关系。 所以,我有以下三个模型: 用户模型: module.exports = { attributes: { name: { type: '
给定一个表定义: Articles: art_id | name -------|-------------- 1 | article1 2 | article2 3
谁能举例说明“em 是相对于字体大小的,% 是相对于父元素的”? 相对于字体大小和相对于父元素是什么意思? 最佳答案 考虑一下您是否要在另一个框内定义一个框的高度。如果您将高度指定为 50%,它将是包
我有一个多对多关系,当我加载位于此关系一侧的实体时,我希望将另一侧相关实体的 ArrayCollection 视为其属性。然而,这并没有发生——加载的 ArrayCollection 中没有任何元素,
Relation#update(id, attributes) 文档提到“无论对象是否成功保存到数据库,都会返回结果对象。”,而 Relation#update_all (updates, condi
我是一名优秀的程序员,十分优秀!