Kaporch
asked on
ASP .net datagrid - hyperlink column to add/edit information in the grid in a new window
I have the following code in a grid in my ASP .net page to create a grid with a hyperlink column:
<ASP:DATAGRID id="dgComplianceNotes" runat="server" autogeneratecolumns="False " CellPadding="5"
OnPreRender="dgComplianceN otes_PreRe nder" cssClass="datagrid" GridLines="Vertical" Height="120px">
<HeaderStyle ForeColor="White" CssClass="dgHeader"></Head erStyle>
<Columns>
<asp:BoundColumn DataField="Owner" HeaderText="User"></asp:Bo undColumn>
<asp:BoundColumn DataField="RevisedDate" HeaderText="Date/Time"></a sp:BoundCo lumn>
<asp:BoundColumn DataField="RecordedNotes" HeaderText="Note"></asp:Bo undColumn>
<asp:BoundColumn Visible="False" DataField="NoteNumber" HeaderText="NoteNumber"></ asp:BoundC olumn>
<asp:HyperLinkColumn Target="_blank" DataNavigateUrlField="Note Number" DataNavigateUrlFormatStrin g="notesed it?n={0}"
DataTextField="Edit" HeaderText="Edit"></asp:Hy perLinkCol umn>
</Columns>
</ASP:DATAGRID>
It opens up a new page when I click on the hyperlink. After the user clicks on the hyperlink and changes information on the popup window, I want to post the changes back to the datagrid. How can I do this?
<ASP:DATAGRID id="dgComplianceNotes" runat="server" autogeneratecolumns="False
OnPreRender="dgComplianceN
<HeaderStyle ForeColor="White" CssClass="dgHeader"></Head
<Columns>
<asp:BoundColumn DataField="Owner" HeaderText="User"></asp:Bo
<asp:BoundColumn DataField="RevisedDate" HeaderText="Date/Time"></a
<asp:BoundColumn DataField="RecordedNotes" HeaderText="Note"></asp:Bo
<asp:BoundColumn Visible="False" DataField="NoteNumber" HeaderText="NoteNumber"></
<asp:HyperLinkColumn Target="_blank" DataNavigateUrlField="Note
DataTextField="Edit" HeaderText="Edit"></asp:Hy
</Columns>
</ASP:DATAGRID>
It opens up a new page when I click on the hyperlink. After the user clicks on the hyperlink and changes information on the popup window, I want to post the changes back to the datagrid. How can I do this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just to add a little something. I agree with Rodrigo's method.
If you are using a popup though you would need Javascript to refresh the page which opened the popup for the Page_Load to be fired again.
Thus you would see the changes inside you GridView take place
Andrew
If you are using a popup though you would need Javascript to refresh the page which opened the popup for the Page_Load to be fired again.
Thus you would see the changes inside you GridView take place
Andrew
ASKER
I know how to open a window using Javascript...I've done this before. But how to call the Javascript method to open up the popup window from the datagrid?
Good question. When i have to popup something in my websites, i use UserControl and load it dinamicaly. So i have a reference to it, and can improve the data management on my website. Particulary i dont use much javascript on my code, only when absolutely very necessary.
Here is how you do it.
protected
void gvResults_SelectedIndexCha nged(objec t sender, EventArgs e)
{
string authid = this.gvResults.SelectedVal ue.ToStrin g();
EAD.Utility.
StateManager.HoldSessionLe velValue(t his.Sessio n, "AuthID", authid);
DataTable dt = DoSearch(ddSearch.Selected Value);
BindGridData(dt);
HtmlGenericControl body = (HtmlGenericControl)Page.M aster.Find Control("M asterBody" );
body.Attributes.Add(
"onload", "newwindow('pAuthReport.as px');");
}
http://forums.asp.net/p/988821/1282010.aspx#1282010
protected
void gvResults_SelectedIndexCha
{
string authid = this.gvResults.SelectedVal
EAD.Utility.
StateManager.HoldSessionLe
DataTable dt = DoSearch(ddSearch.Selected
BindGridData(dt);
HtmlGenericControl body = (HtmlGenericControl)Page.M
body.Attributes.Add(
"onload", "newwindow('pAuthReport.as
}
http://forums.asp.net/p/988821/1282010.aspx#1282010
ASKER
I'm not sure how to pass in the noteid from the row in the grid to use as part of the query string. I'm actually going to need to pass in 4 values through the query string, and I don't know how to retrieve these values from the grid.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've finally gotten back to this question -- how would I modify the grid? I tried doing this:
<ASP:DATAGRID id="dgComplianceNotes" runat="server" autogeneratecolumns="False " CellPadding="5"
OnPreRender="dgComplianceN otes_PreRe nder" oneditcommand="Edit_dgComp lianceNote s" cssClass="datagrid" GridLines="Vertical"
Height="120px" runat="server">
<HeaderStyle ForeColor="White" CssClass="dgHeader"></Head erStyle>
<Columns>
<asp:BoundColumn DataField="Owner" HeaderText="User"></asp:Bo undColumn>
<asp:BoundColumn DataField="RevisedDate" HeaderText="Date/Time"></a sp:BoundCo lumn>
<asp:BoundColumn DataField="RecordedNotes" HeaderText="Note"></asp:Bo undColumn>
<asp:BoundColumn Visible="False" DataField="NoteNumber" HeaderText="NoteNumber"></ asp:BoundC olumn>
<ASP:EDITCOMMANDCOLUMN headertext="Edit" itemstyle-horizontalalign= "Right" edittext="Edit"></ASP:EDIT COMMANDCOL UMN>
</Columns>
</ASP:DATAGRID>
to try to create an edit column, but I'm getting an error that I need a runat = server tag, which I did include.
<ASP:DATAGRID id="dgComplianceNotes" runat="server" autogeneratecolumns="False
OnPreRender="dgComplianceN
Height="120px" runat="server">
<HeaderStyle ForeColor="White" CssClass="dgHeader"></Head
<Columns>
<asp:BoundColumn DataField="Owner" HeaderText="User"></asp:Bo
<asp:BoundColumn DataField="RevisedDate" HeaderText="Date/Time"></a
<asp:BoundColumn DataField="RecordedNotes" HeaderText="Note"></asp:Bo
<asp:BoundColumn Visible="False" DataField="NoteNumber" HeaderText="NoteNumber"></
<ASP:EDITCOMMANDCOLUMN headertext="Edit" itemstyle-horizontalalign=
</Columns>
</ASP:DATAGRID>
to try to create an edit column, but I'm getting an error that I need a runat = server tag, which I did include.
<asp:DataGrid runat="server" id="DataGrid2"
Font-Name="Verdana" Font-Size="9pt" CellPadding="5"
AlternatingItemStyle-BackC olor="#ddd ddd"
Font-Names="Verdana" OnEditCommand="DataGrid2_E ditCommand " OnUpdateCommand="DataGrid2 _UpdateCom mand" OnCancelCommand="DataGrid2 _CancelCom mand" >
<HeaderStyle BackColor="Navy" ForeColor="White" Font-Size="13pt"
Font-Bold="True" HorizontalAlign="Center" />
<Columns>
<asp:EditCommandColumn CancelText="Cancel" EditText="Edit" UpdateText="Update"></asp: EditComman dColumn>
</Columns>
<AlternatingItemStyle BackColor="#DDDDDD" />
</asp:DataGrid>
Here is your grid with all 3 buttons for edit,update,cancel
Try putting this.
Make sure you delete the event form this code which you are not handling right now.
Font-Name="Verdana" Font-Size="9pt" CellPadding="5"
AlternatingItemStyle-BackC
Font-Names="Verdana" OnEditCommand="DataGrid2_E
<HeaderStyle BackColor="Navy" ForeColor="White" Font-Size="13pt"
Font-Bold="True" HorizontalAlign="Center" />
<Columns>
<asp:EditCommandColumn CancelText="Cancel" EditText="Edit" UpdateText="Update"></asp:
</Columns>
<AlternatingItemStyle BackColor="#DDDDDD" />
</asp:DataGrid>
Here is your grid with all 3 buttons for edit,update,cancel
Try putting this.
Make sure you delete the event form this code which you are not handling right now.
ASKER
Getting this message:
Control 'dgComplianceNotes__ctl2__ ctl0' of type 'DataGridLinkButton' must be placed inside a form tag with runat=server.
My page looks like this:
<body leftMargin="0" topMargin="0" onload="LoadPage();MM_prel oadImages( '/images/h eader/meet ings_over. jpg','/ima ges/header /speakers_ over.jpg', '/images/h eader/atte ndees_over .jpg','/im ages/heade r/venues_o ver.jpg',' /images/he ader/resou rces_over. jpg','/ima ges/header /help_over .jpg','/im ages/heade r/feedback _over.jpg' ,'/images/ header/log out_over.j pg')">
<FORM id="mynotes" method="post" runat="server">
<UC1:HEADER id="Header1" runat="server"></UC1:HEADE R></FORM>
<TABLE class="watermark_bg" height="80%" cellSpacing="0" cellPadding="0" width="95%" align="center">
<TBODY>
<TR>
<TD>
<table height="100%" cellSpacing="0" cellPadding="0" width="100%">
<TBODY>
<TR>
<TD class="meetingnav" vAlign="top" width="150">
<table cellSpacing="0" cellPadding="5" width="95%">
<tr>
<td align="left" colSpan="2"><A class="meetingnav" href="\meetings\meetingdet ail.aspx"> Meeting
Detail</A>
</td>
</tr>
<NAVIGATOR:NAVIGATOR id="ucLeft" runat="server"></NAVIGATOR :NAVIGATOR ></table>
</TD>
<td>
<TD vAlign="top"><ASP:TABLE id="tblComplianceNotes" runat="server" cssclass="meetinginfo" width="100%" cellspacing="0"
visible="False">
<ASP:TABLEROW>
<ASP:TABLECELL>
<ASP:LABEL CssClass="orangeheaderleft ">Novus Notes</ASP:LABEL>
</ASP:TABLECELL>
</ASP:TABLEROW>
<ASP:TABLEROW>
<ASP:TABLECELL>
<ASP:DATAGRID id="dgComplianceNotes" runat="server" Height="120px" GridLines="Vertical" cssClass="datagrid"
OnPreRender="dgComplianceN otes_PreRe nder" oneditcommand="Edit_dgComp lianceNote s" CellPadding="5" autogeneratecolumns="False ">
<HeaderStyle ForeColor="White" CssClass="dgHeader" runat="server"></HeaderSty le>
<Columns>
<asp:BoundColumn DataField="Owner" HeaderText="User"></asp:Bo undColumn>
<asp:BoundColumn DataField="RevisedDate" HeaderText="Date/Time"></a sp:BoundCo lumn>
<asp:BoundColumn DataField="RecordedNotes" HeaderText="Note"></asp:Bo undColumn>
<asp:BoundColumn Visible="False" DataField="NoteNumber" HeaderText="NoteNumber"></ asp:BoundC olumn>
<asp:EditCommandColumn EditText="Edit" HeaderText="Edit"></asp:Ed itCommandC olumn>
</Columns>
</ASP:DATAGRID>
</ASP:DATAGRID>
</ASP:TABLECELL>
</ASP:TABLEROW>
</ASP:TABLE></TD>
</TR>
<tr>
<td> </td>
</tr>
</TBODY>
</table>
</TD>
</TR>
</TBODY>
</TABLE>
</TD></TR></TABLE>
<UC2:FOOTER id="Footer1" runat="server"></UC2:FOOTE R></FORM>< /TR></TBOD Y></TABLE> </TR></TBO DY></TABLE >
</body>
</HTML>
Control 'dgComplianceNotes__ctl2__
My page looks like this:
<body leftMargin="0" topMargin="0" onload="LoadPage();MM_prel
<FORM id="mynotes" method="post" runat="server">
<UC1:HEADER id="Header1" runat="server"></UC1:HEADE
<TABLE class="watermark_bg" height="80%" cellSpacing="0" cellPadding="0" width="95%" align="center">
<TBODY>
<TR>
<TD>
<table height="100%" cellSpacing="0" cellPadding="0" width="100%">
<TBODY>
<TR>
<TD class="meetingnav" vAlign="top" width="150">
<table cellSpacing="0" cellPadding="5" width="95%">
<tr>
<td align="left" colSpan="2"><A class="meetingnav" href="\meetings\meetingdet
Detail</A>
</td>
</tr>
<NAVIGATOR:NAVIGATOR id="ucLeft" runat="server"></NAVIGATOR
</TD>
<td>
<TD vAlign="top"><ASP:TABLE id="tblComplianceNotes" runat="server" cssclass="meetinginfo" width="100%" cellspacing="0"
visible="False">
<ASP:TABLEROW>
<ASP:TABLECELL>
<ASP:LABEL CssClass="orangeheaderleft
</ASP:TABLECELL>
</ASP:TABLEROW>
<ASP:TABLEROW>
<ASP:TABLECELL>
<ASP:DATAGRID id="dgComplianceNotes" runat="server" Height="120px" GridLines="Vertical" cssClass="datagrid"
OnPreRender="dgComplianceN
<HeaderStyle ForeColor="White" CssClass="dgHeader" runat="server"></HeaderSty
<Columns>
<asp:BoundColumn DataField="Owner" HeaderText="User"></asp:Bo
<asp:BoundColumn DataField="RevisedDate" HeaderText="Date/Time"></a
<asp:BoundColumn DataField="RecordedNotes" HeaderText="Note"></asp:Bo
<asp:BoundColumn Visible="False" DataField="NoteNumber" HeaderText="NoteNumber"></
<asp:EditCommandColumn EditText="Edit" HeaderText="Edit"></asp:Ed
</Columns>
</ASP:DATAGRID>
</ASP:DATAGRID>
</ASP:TABLECELL>
</ASP:TABLEROW>
</ASP:TABLE></TD>
</TR>
<tr>
<td> </td>
</tr>
</TBODY>
</table>
</TD>
</TR>
</TBODY>
</TABLE>
</TD></TR></TABLE>
<UC2:FOOTER id="Footer1" runat="server"></UC2:FOOTE
</body>
</HTML>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I had placed the end form on the bottom of the page but I think ASP .net moved it.
ASKER
I am using Visual Studio 2003 and the gridviewrow is not available. Any other way to get the individual values in the grid?
ASKER
1.1 Framework
ASKER
Okay, I found it by viewing another solution and modifying the code a little bit:
e.Item.Cells[3].Text
e.Item.Cells[3].Text
I think problem is getting worst than it is. Any way
Can you create any button like this.
<asp:HyperLink ID="lbltaskname" runat="server" Font-Bold="false" Font-Size="small"
Height="20" NavigateUrl='<%# FormatUrl( (string) Eval("Courseid" ),(string) Eval("sectionid")) %>'
Text='<%# Eval("sectionid") %>' Width="40"></asp:HyperLink >
In your datagrid. here in navigate url in EVAL statement you will put the desired column names you want to pass as query string.
On cs page write this.
protected string FormatUrl(string courseid, string sectionid)
{
return "nextpage.aspx?sectionid=" + courseid + sectionid ;
}
This should be all.
-------------------
If this doesn't work will create one example for you.
Can you create any button like this.
<asp:HyperLink ID="lbltaskname" runat="server" Font-Bold="false" Font-Size="small"
Height="20" NavigateUrl='<%# FormatUrl( (string) Eval("Courseid" ),(string) Eval("sectionid")) %>'
Text='<%# Eval("sectionid") %>' Width="40"></asp:HyperLink
In your datagrid. here in navigate url in EVAL statement you will put the desired column names you want to pass as query string.
On cs page write this.
protected string FormatUrl(string courseid, string sectionid)
{
return "nextpage.aspx?sectionid="
}
This should be all.
-------------------
If this doesn't work will create one example for you.
ASKER
I think your code might actually transfer the main page to another page, which is not what I want to do.
Ok now lets restart.
What you have and what you want to achieve ?
What you have and what you want to achieve ?
You want an editable datagrid ? If yes in what way from datasoruce or dynamically ?
You have datagrid filled with values. And on some button click retaining (OUTSIDE/INSIDE) the datagrid you want to get some of the values from the filled dataset ?
You have datagrid filled with values. And on some button click retaining (OUTSIDE/INSIDE) the datagrid you want to get some of the values from the filled dataset ?
ASKER
I have a datagrid that contains values from the datagrid. On the datagrid is a button which says 'Edit'. When the user clicks on the button, a popup window should appear and allow the user to edit one field that's in the parent window. After the popup window changes are saved to the database and the popup window is closed, I want the parent window to have its grid refreshed. I think I have the basic building blocks of what I need from the responses here, first I have to try it out (& divy out points for multiple helps!)
Thats good. Let us know if anything goes wrong.
Like this:
After adding the changes to the session:
protected void Page_Load(object sender, EventArgs e)
{
if(Session["Changes"] != null
{
string[] changes = ((string[])Session["Change
yourGrid.Items[x]["colunas
yourGrid.Items[x]["linhas"
}
}
This is an idea of how can you do it. Surely there are another way for doing it, but it doesn't come to my mind right now.
Regards, Rodrigo Leote.