Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > ASP > GridView, динамический TextBox, его значение


Автор: AntonL 2.3.2011, 16:41
Здравствуйте.
Создаю кнопку и текстбокс в Gridview и обработку событий примерно так
(
Gridview - заполняется автоматически
в RowCreated и RowDataBound только меняю тип некоторых полей
)

Код

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
  ShowSelectTab(e);

       }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            ShowSelectTab(e);

        }
private void ShowSelectTab(GridViewRowEventArgs e)
        {
           TextBox PasswordTextBox = new TextBox();

            PasswordTextBox.ID = "PasswordTextBox";// +e.Row.Cells[0].Text;
            e.Row.Cells[1].Controls.Add(PasswordTextBox);
           

            Button SetPasswordBtn = new Button();
            SetPasswordBtn.Text = e.Row.Cells[3].Text;
            SetPasswordBtn.CommandName = e.Row.Cells[0].Text + ":" + e.Row.RowIndex;
            SetPasswordBtn.ID = "SetPasswordBtn" + e.Row.Cells[0].Text;
            SetPasswordBtn.Command += new CommandEventHandler(SetPasswordBtn_Command);

            e.Row.Cells[3].Controls.Add(SetPasswordBtn);

}

 void SetPasswordBtn_Command(object sender, CommandEventArgs e)
        {
            int index = Convert.ToInt32(e.CommandName.Split(':')[1]);
            int OperID = Convert.ToInt32(e.CommandName.Split(':')[0]);

            GridViewRow row = GridView1.Rows[index];
            string TxtBox = ((TextBox)row.Cells[1].FindControl("PasswordTextBox")).Text;
          Response.Write(TxtBox);
}


Значение поля TextBox всегда пустое. Как при нажатие кнопки получить то что ввели в TextBox? 

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)