【问题标题】:How to enable all textbox controls in itemtemplate of Repeater by itemCommand?如何通过itemCommand启用Repeater的itemtemplate中的所有文本框控件?
【发布时间】:2015-05-21 02:18:47
【问题描述】:

我有一个中继器,我使用标签进行显示,并使用一个隐藏的文本框来保存相同的值。现在我想启用文本框,以便用户可以编辑表/中继器中的输入。谁能帮我?下面是我的代码

public void FillTable()
{

    DataTable table = new DataTable();
    using (MySqlConnection conn = Functions.GetConnection())
    {

        string sql = "SELECT FirstName, LastName from tbluser LIMIT 15";



        using (MySqlCommand cmd = new MySqlCommand(sql, conn))
        {
            MySqlDataAdapter da = new MySqlDataAdapter();

            da.SelectCommand = cmd;
            da.Fill(table);
            conn.Close();
        }
    }
    asd.DataSource = table;
    asd.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
    asd.Visible = true;
}

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    RepeaterItem item = e.Item;

    Literal lblname = (Literal)item.FindControl("Label2");
    TextBox txtbox = (TextBox)item.FindControl("Label3");




    if (e.CommandName == "EDIT")
    {
            lblname.Visible = false;
            txtbox.Visible = true;

【问题讨论】:

  • 我找到了解决方案,我使用引导模式编辑表中的记录(asp.net 中继器)。在 itemCommand 事件中,我获取 ID 并检索该记录,然后绑定到模式文本框中。但是,如果有内联方法,我想知道。干杯,

标签: c# asp.net repeater itemtemplate


【解决方案1】:

您没有获得文本框,而是两次获得标签:

 TextBox txtbox = (TextBox)item.FindControl("Label3");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-05
    相关资源
    最近更新 更多