D
David Ching
Newbie question here. I have a GridView where I show all the records in my
table. I have Edit links in each row to edit that row, and also a button to
Insert a new record. In both cases, I'd like to popup a <div> containing a
DetailsView to specify the record data. The <div> is popped up when the
Insert button is clicked as per this JavaScript:
<button
onclick="document.getElementById('divAdd').style.display='block';return
false;">
or when an Edit link is clicked:
protected void grdMaster_RowCreated(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lnkEdit = (LinkButton)e.Row.Cells[0].Controls[0];
lnkEdit.Attributes["onclick"] =
"document.getElementById('divAdd').style.display='block';return false;";
}
}
The <div> is :
<div id="divAdd" class="popupWindow">
<h3>Add Project</h3>
<asp
etailsView
id="frmAdd"
DataSourceId="srcProjects"
DefaultMode="Edit"
AutoGenerateEditButton="True"
Runat="server" AutoGenerateRows="False" DataKeyNames="ProjectId">
<Fields>
<asp:boundfield DataField="ProjectName" HeaderText="Project Name"/>
<asp:TemplateField HeaderText="Client Name">
<ItemTemplate>
<asp
ropDownList ID="DropDownList1"
DataSourceID="srcClients"
DataTextField="ClientName"
DataValueField="ClientId"
SelectedValue='<%# Bind("ClientId")%>'
Runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:boundfield DataField="ProjectPONumber" HeaderText="PO Number"/>
</Fields>
</asp
etailsView>
</div>
I have verified that this <div> works for the Edit case! It also works for
the Insert case, if I change these two lines:
DefaultMode="Edit"
AutoGenerateEditButton="True"
to:
DefaultMode="Insert"
AutoGenerateInsertButton="True"
But how can I set these programatically depending on whether an Edit link is
clicked, or the Insert button is clicked? All the examples I've seen have 2
<div>, one for the Edit, and another one for the Insert. But this seems
wasteful and error-prone because only the above 2 lines are different. Is
there any way to use just one <div> for both Edit and Insert?
Thanks a bunch,
David
table. I have Edit links in each row to edit that row, and also a button to
Insert a new record. In both cases, I'd like to popup a <div> containing a
DetailsView to specify the record data. The <div> is popped up when the
Insert button is clicked as per this JavaScript:
<button
onclick="document.getElementById('divAdd').style.display='block';return
false;">
or when an Edit link is clicked:
protected void grdMaster_RowCreated(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lnkEdit = (LinkButton)e.Row.Cells[0].Controls[0];
lnkEdit.Attributes["onclick"] =
"document.getElementById('divAdd').style.display='block';return false;";
}
}
The <div> is :
<div id="divAdd" class="popupWindow">
<h3>Add Project</h3>
<asp
id="frmAdd"
DataSourceId="srcProjects"
DefaultMode="Edit"
AutoGenerateEditButton="True"
Runat="server" AutoGenerateRows="False" DataKeyNames="ProjectId">
<Fields>
<asp:boundfield DataField="ProjectName" HeaderText="Project Name"/>
<asp:TemplateField HeaderText="Client Name">
<ItemTemplate>
<asp
DataSourceID="srcClients"
DataTextField="ClientName"
DataValueField="ClientId"
SelectedValue='<%# Bind("ClientId")%>'
Runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:boundfield DataField="ProjectPONumber" HeaderText="PO Number"/>
</Fields>
</asp
</div>
I have verified that this <div> works for the Edit case! It also works for
the Insert case, if I change these two lines:
DefaultMode="Edit"
AutoGenerateEditButton="True"
to:
DefaultMode="Insert"
AutoGenerateInsertButton="True"
But how can I set these programatically depending on whether an Edit link is
clicked, or the Insert button is clicked? All the examples I've seen have 2
<div>, one for the Edit, and another one for the Insert. But this seems
wasteful and error-prone because only the above 2 lines are different. Is
there any way to use just one <div> for both Edit and Insert?
Thanks a bunch,
David