이 당신이 행 추가하면 매우 간단하다 : 영업 이익
gv.EditIndex = gv.Rows.Count-1;
편집 :
을 당신은 새로 추가 된 행의 편집 인덱스를 설정해야
이 코드는 더티 코드이며, 나는 단지 내가 의미하는 바를 보여 주며 그것을 상당히 빨리 채찍질합니다. 페이지에 GridView1라는있는 gridview를 가정 : 우리는 그리드 뷰를 결합
namespace HelpSO3
{
public partial class _Default : System.Web.UI.Page
{
List<string> t = new List<string>();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string s = "hi";
t.Add(s);
GridView1.DataSource = t;
GridView1.DataBind();
Session["MyList"] = t;
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
t = (List<string>)Session["MyList"];
t.Add("Another String");
GridView1.DataSource = t;
GridView1.DataBind();
GridView1.EditIndex = GridView1.Rows.Count - 1;
GridView1.DataBind();
Session["MyList"] = t;
}
}
}
그래서 Button1_Click 이벤트는 값이 "또 다른 문자열"로 새 행을 추가하고 새로운 행으로
EditIndex
값을 설정하고 바인딩. 간단합니다. 귀하의 경우에는
은 당신의 코드가 될 것이다 :
protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Insert") //- this is needed to explain that the INSERT command will only work when INSERT is clicked
{
dbcon.Execute("INSERT INTO PROJ_ASP (TRANS_CD) VALUES('')", "ProjectASPConnectionString");
gv.DataBind();
gv.EditIndex = gv.Rows.Count-1;
gv.DataBind();
}
}
웹, Winforms 또는 WPF는 어떤 플랫폼입니까? 그리고 더 중요한 것은 지금까지 무엇을 시도 했습니까? 귀하의 질문은 많은 문제를 해결하기 위해 많은 노력을 기울이지는 않습니다. 많은 노력을 기울이지는 않습니다. –
이것은 웹 응용 프로그램입니다. – KKP
@MichaelYounani - 새로 추가 된 행의 인덱스가 필요하고'EditIndex' 속성을 설정하십시오. 내 대답을 참조하십시오. – JonH