Link to home
Start Free TrialLog in
Avatar of Kaporch
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="dgComplianceNotes_PreRender" cssClass="datagrid" GridLines="Vertical" Height="120px">
                                                                        <HeaderStyle ForeColor="White" CssClass="dgHeader"></HeaderStyle>
                                                                        <Columns>
                                                                              <asp:BoundColumn DataField="Owner" HeaderText="User"></asp:BoundColumn>
                                                                              <asp:BoundColumn DataField="RevisedDate" HeaderText="Date/Time"></asp:BoundColumn>
                                                                              <asp:BoundColumn DataField="RecordedNotes" HeaderText="Note"></asp:BoundColumn>
                                                                              <asp:BoundColumn Visible="False" DataField="NoteNumber" HeaderText="NoteNumber"></asp:BoundColumn>
                                                                              <asp:HyperLinkColumn Target="_blank" DataNavigateUrlField="NoteNumber" DataNavigateUrlFormatString="notesedit?n={0}"
                                                                                    DataTextField="Edit" HeaderText="Edit"></asp:HyperLinkColumn>
                                                                        </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
Avatar of chinu1310
chinu1310
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can have an array with your changes, and add it to the Session. After making the changes, you do the redirection to the page which contains your Grid. On Load of your grid's page, you get the changes added to the session.

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["Changes"]);
     yourGrid.Items[x]["colunas"] = changes[0];
     yourGrid.Items[x]["linhas"] = changes[1];
  }
}

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.
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
Avatar of Kaporch
Kaporch

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_SelectedIndexChanged(object sender, EventArgs e)

{

string authid = this.gvResults.SelectedValue.ToString();

EAD.Utility.
StateManager.HoldSessionLevelValue(this.Session, "AuthID", authid);

DataTable dt = DoSearch(ddSearch.SelectedValue);

BindGridData(dt);

HtmlGenericControl body = (HtmlGenericControl)Page.Master.FindControl("MasterBody");

body.Attributes.Add(
"onload", "newwindow('pAuthReport.aspx');");

}
http://forums.asp.net/p/988821/1282010.aspx#1282010
Avatar of Kaporch

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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kaporch

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="dgComplianceNotes_PreRender" oneditcommand="Edit_dgComplianceNotes" cssClass="datagrid" GridLines="Vertical"
                                                                        Height="120px" runat="server">
                                                                        <HeaderStyle ForeColor="White" CssClass="dgHeader"></HeaderStyle>
                                                                        <Columns>
                                                                              <asp:BoundColumn DataField="Owner" HeaderText="User"></asp:BoundColumn>
                                                                              <asp:BoundColumn DataField="RevisedDate" HeaderText="Date/Time"></asp:BoundColumn>
                                                                              <asp:BoundColumn DataField="RecordedNotes" HeaderText="Note"></asp:BoundColumn>
                                                                              <asp:BoundColumn Visible="False" DataField="NoteNumber" HeaderText="NoteNumber"></asp:BoundColumn>
                                                                              <ASP:EDITCOMMANDCOLUMN headertext="Edit" itemstyle-horizontalalign="Right" edittext="Edit"></ASP:EDITCOMMANDCOLUMN>
                                                                        </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-BackColor="#dddddd"
       
    Font-Names="Verdana" OnEditCommand="DataGrid2_EditCommand" OnUpdateCommand="DataGrid2_UpdateCommand" OnCancelCommand="DataGrid2_CancelCommand"    >
 
     <HeaderStyle BackColor="Navy" ForeColor="White" Font-Size="13pt"
               Font-Bold="True" HorizontalAlign="Center" />
 
     <Columns>
         <asp:EditCommandColumn CancelText="Cancel" EditText="Edit" UpdateText="Update"></asp:EditCommandColumn>
       
     </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.
Avatar of Kaporch

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_preloadImages('/images/header/meetings_over.jpg','/images/header/speakers_over.jpg','/images/header/attendees_over.jpg','/images/header/venues_over.jpg','/images/header/resources_over.jpg','/images/header/help_over.jpg','/images/header/feedback_over.jpg','/images/header/logout_over.jpg')">
            <FORM id="mynotes" method="post" runat="server">
                  <UC1:HEADER id="Header1" runat="server"></UC1:HEADER></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\meetingdetail.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="dgComplianceNotes_PreRender" oneditcommand="Edit_dgComplianceNotes" CellPadding="5" autogeneratecolumns="False">
                                                                                    <HeaderStyle ForeColor="White" CssClass="dgHeader" runat="server"></HeaderStyle>
                                                                                    <Columns>
                                                                                          <asp:BoundColumn DataField="Owner" HeaderText="User"></asp:BoundColumn>
                                                                                          <asp:BoundColumn DataField="RevisedDate" HeaderText="Date/Time"></asp:BoundColumn>
                                                                                          <asp:BoundColumn DataField="RecordedNotes" HeaderText="Note"></asp:BoundColumn>
                                                                                          <asp:BoundColumn Visible="False" DataField="NoteNumber" HeaderText="NoteNumber"></asp:BoundColumn>
                                                                                          <asp:EditCommandColumn EditText="Edit" HeaderText="Edit"></asp:EditCommandColumn>
                                                                                    </Columns>
                                                                              </ASP:DATAGRID>
                                                                  </ASP:DATAGRID>
                                                                  </ASP:TABLECELL>
                                                                  </ASP:TABLEROW>
                                                            </ASP:TABLE></TD>
                                                </TR>
                                                <tr>
                                                      <td>&nbsp;</td>
                                                </tr>
                                          </TBODY>
                                    </table>
                              </TD>
                        </TR>
                  </TBODY>
            </TABLE>
            </TD></TR></TABLE>
            <UC2:FOOTER id="Footer1" runat="server"></UC2:FOOTER></FORM></TR></TBODY></TABLE></TR></TBODY></TABLE>
      </body>
</HTML>
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kaporch

ASKER

I had placed the end form on the bottom of the page but I think ASP .net moved it.
Avatar of Kaporch

ASKER

I am using Visual Studio 2003 and the gridviewrow is not available.  Any other way to get the individual values in the grid?
Avatar of Kaporch

ASKER

1.1 Framework
Avatar of Kaporch

ASKER

Okay, I found it by viewing another solution and modifying the code a little bit:

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.
Avatar of Kaporch

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

Avatar of Kaporch

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.