asp.net VB 需要为Listview或SQL Insert设置默认值

问题描述 投票:0回答:2

希望我能说清楚。我有:

带有 sql 数据源的 Listview 一个单独的下拉列表,当选择某些内容时会过滤列表视图/sqldatasoure

我想做的是使用下拉列表中的值来设置插入记录的默认值。我看到两个地方,要么是列表视图项插入上的文本框,要么是 sqldatasource Insertparameter 上的默认值。

我尝试了下拉事件中的会话变量,但如果我设置文本框,它会在刷新列表视图后被擦除。似乎没有办法在 sqldatasource 上设置 insertparamater。

我正在尝试找到要设置的正确事件和属性。当我直接引用文本框或在未设置对象或块变量的情况下使用 findcontrol 时,到目前为止我尝试过的所有操作都会出错。换句话说,.net 层次结构让我非常沮丧。

希望这是有道理的。

谢谢

asp.net vb.net listview sqldatasource
2个回答
0
投票

如果我误解了,请道歉,但是您不能更新下拉列表的

DefaultValue
事件中插入参数的
OnSelectedIndexChanged
吗?

<asp:DropDownList runat="server" id="ddl" OnSelectedIndexChanged="ddl_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>

Protected Sub ddl_SelectedIndexChanged(sender As Object, e As EventArgs)

      MySqlDataSource.InsertParameters("ParameterName").DefaultValue = ddl.SelectedValue

End Sub

0
投票

桑蒂, 感谢您的回复,它帮助我思考,您走在正确的道路上。我的下拉列表将值存储在会话变量中,然后检查 ListView 的 ItemInserting 上的文本框,如果它为空,则将数据源设置为会话变量。类似这个

Protected Sub ListView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewInsertEventArgs) Handles ListView1.ItemInserting
        If txtCategoryInsert.Text = "" Then
            SqlDataSource1.InsertParameters("Category").DefaultValue = Session("CatDefault")
        End If
    End Sub
© www.soinside.com 2019 - 2024. All rights reserved.