2009-05-13 6 views

답변

0

효과적으로 테이블에 자 동 번호 열을 추가하고이 값을 사용하여 테이블에서 행의 positino를 결정한 다음이 값을 사용하여 DataGrid의 적절한 행에 영향을줍니다. 원래 질문에서 말한 것처럼 행의 값을 배열에 추가하는 대신 행의 색을 변경하는 것입니다.

public void txtPrice_TextChanged(object sender, EventArgs e) 
{ 
    TextBox txtPrice = (TextBox)sender; 
    DataGridItem myItem = (DataGridItem)txtPrice.Parent.Parent; 
    markRows(myItem, true); 
} 

public void markRows(DataGridItem myItem, bool toSave) 
{ 
    // Prepeare to save this record? 
    CheckBox thisSave = (CheckBox)myItem.FindControl("chkSave"); 
    thisSave.Checked = toSave; 
    // Establish the row's position in the table 
    Label sNo = (Label)myItem.FindControl("SNo"); 
    int rowNum = Convert.ToInt32(sNo.Text) - 1; 
    CheckBox rowSave = (CheckBox)grid.Items[rowNum].FindControl("chkSave"); 

    // Update background color on the row to remove/add highlight 
    if (rowSave.Checked == true) 
     grid.Items[rowNum].BackColor = System.Drawing.Color.GreenYellow; 
    else 
    { 
     Color bgBlue = Color.FromArgb(212, 231, 247); 
     grid.Items[rowNum].BackColor = bgBlue; 
     // some code here to refresh data from table? 
    } 
} 
1

당신은 다음과 같이 경우에 발생하는 TextChanged 이벤트를 얻을 수 있습니다 :

<asp:DataGrid ID="DataGrid1" runat="server" AutoGenerateColumns="False" 
    onitemdatabound="DataGrid1_ItemDataBound"> 
    <Columns> 
     <asp:TemplateColumn HeaderText="Test"> 
      <ItemTemplate> 
       <asp:TextBox OnTextChanged="txtBox_TextChanged" ID="TextBox1" runat="server" AutoPostBack="True"></asp:TextBox> 
      </ItemTemplate> 
     </asp:TemplateColumn> 
     <asp:BoundColumn DataField="Name" HeaderText="Test 1"></asp:BoundColumn> 
    </Columns> 
</asp:DataGrid> 

당신은 내가 다음 속성을 설정해야한다는 것을 알 수 있습니다 : 의 AutoPostBack = "진정한"나는 수동으로 OnTextChanged을 추가 한 = "txtBox_TextChanged"도 텍스트 상자에 추가하십시오. 당신이 입력 한 후 텍스트 상자에 포커스를 잃을 때 이벤트가 발생합니다

protected void txtBox_TextChanged(object sender, EventArgs e) 
{ 
    TextBox txtBox = (TextBox)sender; 
    Label1.Text = txtBox.Text; 
} 

유일한 방법입니다 : 내가 가진 뒤에 내 코드에서

.

고려해야 할 중요한 점 : 이것은 포스트 백을 야기하므로 Ajax는 사용자 경험을 좋게 유지하는 좋은 방법 일 수 있습니다. if (! IsPostBack)에서 DataBind()를 랩핑해야합니다.

희망이 있습니다.

+0

이벤트가 발생하는 데 아무런 문제가 없습니다. 내 문제는 '보낸 사람'텍스트 상자가있는 행을 참조하는 데 있습니다. – fearoffours