C# 웹 응용 프로그램에 GridView 컨트롤이 있습니다. 내 gridview있는 ButtonField 선택, ID="btnSelect"
라는 있습니다. 기본적으로 내 GridView 컨트롤에는 클라이언트 성, 성, 주소 및 전화 번호가 있으며 해당 정보에 대해서는 텍스트 상자가 있습니다. gridview에서 select 버튼을 누르거나 발동 할 때 클라이언트 이름을 텍스트 상자에 넣고 싶습니다. 성공적으로 완료했지만 응용 프로그램에서 최대 6 개의 클라이언트를 선택할 수 있습니다. 제가이 일을하는 것보다 더 좋은 방법이 있습니까? 코드는 다음과 같습니다 : 나는 행 명령에서 선택 버튼을 누르면 때마다, 나는 모든 사람이 만약 문이 복잡 넣어하지 않을 경우 곳으로이 코드에 더 좋은 방법은GridView 컨트롤의 행 명령
void GridView1_RowCommand(Object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[index];
if(string.IsNullOrEmpty(txtName1.Text) && string.IsNullOrEmpty(txtLName1.Text) &&
string.IsNullOrEmpty(txtAddr1.Text) && string.IsNullOrEmpty(txtPhone1.Text))
{
txtName1.Text=Server.HtmlDecode(row.Cells[1].Text);
txtLName1.Text=Server.HtmlDecode(row.Cells[2].Text);
txtAddr1.Text=Server.HtmlDecode(row.Cells[3].Text);
txtPhone1.Text=Server.HtmlDecode(row.Cells[4].Text);
}
//If I hit another select button then this will load the sencond set of txtboxes
if(string.IsNullOrEmpty(txtName2.Text) && string.IsNullOrEmpty(txtLName2.Text) &&
string.IsNullOrEmpty(txtAddr2.Text) && string.IsNullOrEmpty(txtPhone2.Text))
{
txtName2.Text=Server.HtmlDecode(row.Cells[1].Text);
txtLName2.Text=Server.HtmlDecode(row.Cells[2].Text);
txtAddr2.Text=Server.HtmlDecode(row.Cells[3].Text);
txtPhone2.Text=Server.HtmlDecode(row.Cells[4].Text);
}
//The thrid time will load the third button and so on until I fill each txtbox if I choose.
}
있습니까? 이 핸들을 처리 할 수있는 foreach 루프가 있습니까? 모든 지침을 매우 높이 평가할 것입니다!
그것은'txtAddr2'와'txtPhone2'을 위해 일 것이다? – sarwar026
페이지의 모든 컨트롤에서 작동합니다. (다른 컨트롤 안에 있지 않음). "txtName"을 "txtAddr", "txtPhone"등으로 변경해야합니다. 내 코드는 행당 버튼을 가정합니다. 그래서 클릭 한 행은 txt 상자의 행과 일치합니다 – mp3duck
작동하도록했습니다! – Naina