another easy one.

  • Thread starter Thread starter Matt M
  • Start date Start date
M

Matt M

I'm learning today.

So I have a bound datagrid with edit items in it. I've read that in order
to retrieve the values for those edit items (textboxes etc) I can only bind
the grid when NOT postBack.

i.e.
private void Page_Load(object sender, System.EventArgs e)

{

if (!IsPostBack)

{

BindData();

}

}

So my grid initially appears when I go to the page. If I hit the "edit"
link on the grid, the page reloads and the grid doesn't show up. Now, this
makes sense to me, but then how can I get the textbox values on the grid
before the grid binds again.



I'm sure this has been posted before, but I can't seem to find a relevant
answer. Any ideas?

(my code to get the text box values):

dgServices.EditItemIndex = E.Item.ItemIndex;


TextBox editService = (TextBox)
dgServices.Items[dgServices.EditItemIndex].Cells[1].FindControl("edit_Servic
e");

Response.Write(editService .Text);

Any help would be greatly appreciated.

- matt -
 
ah. Solved it myself (well...with the help of
http://aspnet.4guysfromrolla.com/articles/071002-1.2.aspx)

fyi: I made sure that the grid_Edit() binds the data

i.e.
private void Page_Load(object sender, System.EventArgs e)

{

if (!IsPostBack)

{

BindData();

}

}

public void dgServices_Edit(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

{



dgServices.EditItemIndex = e.Item.ItemIndex;

BindData();

}

public void dgServices_Update(object sender,
System.Web.UI.WebControls.DataGridCommandEventArgs E)

{

dgServices.EditItemIndex = E.Item.ItemIndex;


TextBox firstBCTextBox = (TextBox)
dgServices.Items[dgServices.EditItemIndex].Cells[1].FindControl("edit_Servic
e");

Response.Write(dgServices.Items[dgServices.EditItemIndex].Cells[0].Text ) ;

}
 
Back
Top