如何使用overview viewstate在网格视图中的编辑单击按钮上分配动态文本框问题是文本框出现在不同的位置 [英] how to assign a dynamic textbox on edit click button in gridview using overide viewstate The Problem is that the textbox appears at a different location

查看:64
本文介绍了如何使用overview viewstate在网格视图中的编辑单击按钮上分配动态文本框问题是文本框出现在不同的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是将从表格单元格动态创建的文本框分配到单击的gridview行按钮。这是我到目前为止所做的。任何帮助将不胜感激。

< br $> b $ b

What i want to do is to assign a textbox dynamically created from a table cell into a gridview row button clicked.This is what i have done so far.Any help will be appreciated.


protected override object SaveViewState()
{
    var viewState = new object[2];
    //Saving the dropdownlist value to the View State
    viewState[0] = txtmonday.Text;
    return viewState;
}

protected override void LoadViewState(object savedState)
{
    //Getting the dropdown list value from view state.
    if (savedState is object[] && ((object[])savedState).Length == 2)
    {
        var viewState = (object[])savedState;
        //var count = int.Parse(viewState[0].ToString());
        CreateDynamicControl();
        base.LoadViewState(viewState[1]);//cheged from 1 to 0
    }
    else
    {
        base.LoadViewState(savedState);
    }
}


public void CreateDynamicControl()
{
    var txtmonday1 = new TextBox();
    var textboxCell = new TableCell();
    var tableRow = new TableRow();
    tableRow.Cells.Add(textboxCell);
    textboxCell.Controls.Add(txtmonday1);
    tbl.Rows.Add(tableRow);
   // txtmonday1 = (TextBox)txtmonday1;
   // int count = GridView1
   // GridView1.Controls.Add(txtmonday1);



}







protected void btnupdate_Click(object sender, EventArgs e)
{




    foreach (TableRow row in tbl.Rows)
    {
        var textbox = row.Cells[0].Controls[0] as TextBox;
    }





}



protected void btnedit_Click(object sender, EventArgs e)
{

   // txtmonday.ID = "txtmonday1";
    int index = GridView1.EditIndex;

    Button btn = (Button)sender;


    GridViewRow gvr = (GridViewRow)btn.NamingContainer;

    int getindex = gvr.RowIndex;


    string id = GridView1.Rows[getindex].Cells[4].Text;



        TextBox txtmonday = new TextBox();
        txtmonday.ID = "Textbox1";
        string get = GridView1.HeaderRow.Cells[3].Text.ToString();


        txtmonday.Text = GridView1.Rows[getindex].Cells[3].Text;
        Page.Form.Controls.Add(txtmonday);
        GridView1.Rows[getindex].Cells[3].Controls.Add(txtmonday);

}

推荐答案

如果你想在特定单元格中使用txtbox意味着放置文本框在gridview里面的griditemtemplate中,所以当编辑完成后,显示txtbox而不是itemtemplate关联控件
If you want the txtbox in a particular cell means put the textbox in the edititemtemplate in the table which is inside the gridview so when editing is done the txtbox gets displayed instead of the itemtemplate associated control


这篇关于如何使用overview viewstate在网格视图中的编辑单击按钮上分配动态文本框问题是文本框出现在不同的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆