내가 Code Project에 내 질문에 대한 답을 발견
이
내가 지금 내있는 gridview에있는 gridview를 사용
<asp:TemplateField>
<ItemTemplate>
<asp:GridView ID="SubGridView"
GridView의 Extender 때문에 더하기 기호 (링크 참조)를 클릭하면 gridview가 표시됩니다.
페이지로드시 다음을 수행하십시오.
protected void Page_Load(object sender, EventArgs e)
{
GridView1.RowCreated += new GridViewRowEventHandler(GridView1_RowCreated);
GridView1.DataSource = dc.GetLogEntriesWithUsername();
GridView1.DataBind();
이 Gridview에는 이미 DataBound 및 Selected Index Changed 이벤트가 있습니다. i는 다음을 수행하는 열 생성 이벤트
: 또한 데이터 바인딩 및 selectedIndex의 Changed 이벤트가있는 subgridview에서
void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView SubGridView = e.Row.FindControl("SubGridView") as GridView;
List<GetLogEntriesWithUsernameByParentIdResult> subLogEntries = dc.GetLogEntriesWithUsernameByParentId(((GetLogEntriesWithUsernameResult)e.Row.DataItem).logentry_id).ToList();
if (subLogEntries.Count > 0)
{
SubGridView.DataSource = subLogEntries;
SubGridView.DataBind();
(e.Row as ExtGridViewRow).ShowExpand = SubGridView.Rows.Count > 0;
}
}
}
. 이 지금 작동합니다!
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{ // only apply changes if its DataRow
GridView sendingGridView = (GridView)sender;
if (e.Row.RowType == DataControlRowType.DataRow)
{
// when mouse is over the row, save original color to new attribute, and change it to highlight yellow color
e.Row.Attributes.Add("onmouseover",
"this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#C0C0C0';this.style.cursor='pointer';");
// when mouse leaves the row, change the bg color to its original value
e.Row.Attributes.Add("onmouseout",
"this.style.backgroundColor=this.originalstyle;this.style.cursor='cursor'");
//e.Row.Attributes.Add("onclick", ClientScript.GetPostBackClientHyperlink(sendingGridView, "Select$" + e.Row.RowIndex));
e.Row.Cells[1].Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(sendingGridView, "Select$" + e.Row.RowIndex);
e.Row.Cells[2].Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(sendingGridView, "Select$" + e.Row.RowIndex);
e.Row.Cells[3].Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(sendingGridView, "Select$" + e.Row.RowIndex);
e.Row.Cells[4].Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(sendingGridView, "Select$" + e.Row.RowIndex);
e.Row.Cells[5].Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(sendingGridView, "Select$" + e.Row.RowIndex);
그리고 선택된 인덱스 변경 이벤트 :
protected void GridView_SelectedIndexChanged(object sender, EventArgs e)
{
GridView sendingGridView = (GridView)sender;
ViewDetails(Convert.ToInt32(sendingGridView.SelectedDataKey["logentry_id"].ToString()));
}
중 ViewDetails 기능은 다른 사업부에서 선택한 logentry의 세부 정보를 표시
나는이 바인딩 이벤트를 사용합니다. 이제 마지막 단계에서 바쁘다. 행을 클릭하기 전에 데이터를 계속 보여주고있다.
도움 주셔서 감사합니다. 그러나 이것이 내 문제의 해결책입니다.
당신이 이벤트를 발생시키고있는 subgridview가 두 번째 포스트 백에 더 이상 존재하지 않는다고 생각합니다. 그 사건을 일으키지 않는 이유가 될 것입니다 –
그건 꽤 논리적으로 들리 겠지만,이 subgridview를 선택하는 방법도 있어야하지 않아야합니까? – Michael
음 ...동적 컨트롤로 놀았을 때 문제가 더 이상 존재하지 않아서 제 해결 방법은 클라이언트가 실제로 들어오는 것을보기 위해 요청 객체를 검사하고, subgridview를 다시 만들 때이 값을 고려하여 –