datagrid the headache!
-
Hi, Plz tell me how to access the changed values on a datagrid when user pressed update button. I know the normal way : myTextBox.Text=CType(myGrid.cells(1).Controls(0),TextBox).Text But i have dynamic boundColumns that are created by pageLoad. Searched all forums and googled for 2 days..nothing found.. Thanx in advance.. --junior coder--
-
Hi, Plz tell me how to access the changed values on a datagrid when user pressed update button. I know the normal way : myTextBox.Text=CType(myGrid.cells(1).Controls(0),TextBox).Text But i have dynamic boundColumns that are created by pageLoad. Searched all forums and googled for 2 days..nothing found.. Thanx in advance.. --junior coder--
Hi there, You need to make sure that the dynamic column is in the Columns collection of the datagrid when the page posts back, and more importantly it should be readded before the Page_Load event gets fired:
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
BoundColumn col = new BoundColumn();
col.DataField = "CategoryName";
DataGrid1.Columns.AddAt(1, col);BindGrid(); }
}
protected override void LoadViewState(object savedState)
{
base.LoadViewState (savedState);BoundColumn col = new BoundColumn(); col.DataField = "CategoryName"; DataGrid1.Columns.AddAt(1, col);
}
-
Hi, Plz tell me how to access the changed values on a datagrid when user pressed update button. I know the normal way : myTextBox.Text=CType(myGrid.cells(1).Controls(0),TextBox).Text But i have dynamic boundColumns that are created by pageLoad. Searched all forums and googled for 2 days..nothing found.. Thanx in advance.. --junior coder--
-
Hi, Plz tell me how to access the changed values on a datagrid when user pressed update button. I know the normal way : myTextBox.Text=CType(myGrid.cells(1).Controls(0),TextBox).Text But i have dynamic boundColumns that are created by pageLoad. Searched all forums and googled for 2 days..nothing found.. Thanx in advance.. --junior coder--
That was the problem : my columns were lost when page is post back.. I found the way. -I create dynamic textBoxes at pageLoad event . -When user push "Edit" button on template column, i get the values of cells by:
CType(Me.FindControl("Form1").FindControl("nameOfControl"), TextBox).Text = CType(e.Item.Cells(counter).Controls(0), TextBox).Text
-I add attribute of onblur to these textBoxes to get values of changed datagrid cells.virtualTextBox.Attributes.Add("onblur", "document.getElementById('" + nameOfControl & "').value=this.value")
-Then i can use this virtual textBoxes Text properties to update my dataBase:newValue = CType(Me.FindControl("Form1").FindControl(nameOfControl), TextBox).Text()
That 's it.. Thanx again for your helps.. --junior coder--