DetailsView Issue.

M

Midway

Hi there,

I am using a GridView and displaying details in a Detailsview control. Now
then I select a Row in the Gridview the details on for that record shows on
the Detailsview control, but when there is/are not related records on the
detailsview, the detailsview does not show at all. the functionality that I'm
looking for is when I select a Row on the Gridview, if that specific record
does not have a related record or the PrimaryKey does not exist on the
details table, I want the detailsview to automatically goes on Insert Mode so
the user can star creating detail records for the parent record.

Now, how can I tell when the detailsview control did not bring any records
from the database?

Thanks very much.

Midway
 
B

Brennan Stehling

I am not sure I fully understand your question. From what you wrote I
will assume you have not bound your GridView and DetailsView to the
SqlDatasource. When bind them to eachother you would normally do that
so it would ensure they both have the same records.

I do this with the following code:

protected void GridView1_SelectedIndexChanged(object sender,
EventArgs e)
{
DetailsView1.PageIndex = GridView1.SelectedIndex;
DetailsView1.ChangeMode(DetailsViewMode.Edit);
}

To create a new record using the DetailsView, I have added a button to
the page and attached this event handler.

protected void Button1_Click(object sender, EventArgs e)
{
DetailsView1.PageIndex = -1;
DetailsView1.ChangeMode(DetailsViewMode.Insert);
}

That should allow you to insert a new record which you can select from
the GridView and edit in the DetailsView.

Let me know if this is what you needed.

Brennan Stehling
http://brennan.offwhite.net/blog/
 

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,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top