another easy one.

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 -
 
M

Matt M

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 ) ;

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top