Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit form in asp.Net when I have a lookup field 1

Status
Not open for further replies.

123ASP

MIS
Nov 2, 2002
239
0
0
US
hi I have a Datagrid where I click on the id to open another aspx page to edit the selected record. I was able to pass the selected row's id and use it in the second page to pull the record into an edit form. The issue I am facing is I have a lookup field in the selected record and I got stuck not knowing how to show the user the values in the combo box for his/her selection in the edit mode.
Any help is appreciated.
Thanks
Al
 
1. While binding your grid initialy, set the DataKeyField property to the primary key column of the bound recordset, i.e.:
Code:
<asp:DataGrid ID=&quot;myGrid&quot; DataKeyField=&quot;CustomerId&quot;>
2. While handing the EditCommand event, extact the ID of the row to be edited and pass it to the look up page as query string parameter:
Code:
private void myGrid_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
 int customerId	= Convert.ToInt32(myGrid.DataKeys[e.Item.ItemIndex]);
 Server.Transfer(&quot;lookUp.aspx?cid=&quot; + customerId.ToString());	
}
3. In the look up page, populate the controls from the database, then do another hit to get just the edited record by ID you paseed. Use those values to set text and/or list box selections.

Can you use the built-in editing in the grid, without going to a look-up page? Will save you a lot of time.
 
I have been reading about add/edit/delete/sort/paging in a datagrid and I have experienced some samples from the internet. The best one I liked was in this link

This is exactely what I am looking for except that it does not have paging. so what I did, I tried to add the paing feature, but miss up the code and could not run the sample again. if you can help me by showing me how to add the paging feature to the above sample, I would be greatfull and you will save me alot of time to work on other stuff. I have been stuck in trying to have one DG that has all features.
thanks again for your hlep and support
Al
 
Adding paging functionality to a grid is pretty simple:
Code:
<asp:datagrid id=&quot;myGrid&quot; runat=&quot;server&quot; AllowPaging=&quot;True&quot; PageSize=&quot;10&quot;>
 <PagerStyle Mode=&quot;NumericPages&quot; />
.....
code behind:
private void myGrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
 myGrid.CurrentPageIndex = e.NewPageIndex;
 // rebind the grid			
 myGrid.DataSource = yourdatasource;
 myGrid.DataBind();
}
private void InitializeComponent()
{
 this.myGrid.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.myGrid_PageIndexChanged);
}
 
Thanks LV for your contribution. I too have been looking for all-in-one DG. This was exactly what I have been looking for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top