Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 963
  • Last Modified:

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?
0
Kaporch
Asked:
Kaporch
  • 10
  • 8
  • 2
  • +1
3 Solutions
 
chinu1310Commented:
Have a look at this javascript article.
http://aspalliance.com/627

Exactly what you wanted.

Hope it helps.
0
 
NeotkCommented:
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.
0
 
REA_ANDREWCommented:
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
KaporchAuthor Commented:
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?  
0
 
NeotkCommented:
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.
0
 
chinu1310Commented:
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
0
 
KaporchAuthor Commented:
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.
0
 
chinu1310Commented:
This is how you get it.

protected void Grid1_SelectedIndexChanged1(object sender, EventArgs e)
    {
        GridViewRow dr = Grid1.SelectedRow;
        string valiue = dr.Cells[1].Text;
       string value1  = dr.Cells[2].Text;
//TAKE WHATEVER VALUES YOU WANT
    }
0
 
KaporchAuthor Commented:
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.
0
 
chinu1310Commented:
<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.
0
 
KaporchAuthor Commented:
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>
0
 
REA_ANDREWCommented:
You end your form too early

            <FORM id="mynotes" method="post" runat="server">
                  <UC1:HEADER id="Header1" runat="server"></UC1:HEADER></FORM>

Your Form tag should encapsulate everything that is server side.  So best practice is to follow this design

<body>
<form runat="server">
<!-- EVERYHTHING ELSE IN YOUR DOT NET PAGE BETWEEN HERE that requires a form tag -->
</form>
</body>

Andrew
0
 
KaporchAuthor Commented:
I had placed the end form on the bottom of the page but I think ASP .net moved it.
0
 
KaporchAuthor Commented:
I am using Visual Studio 2003 and the gridviewrow is not available.  Any other way to get the individual values in the grid?
0
 
KaporchAuthor Commented:
1.1 Framework
0
 
KaporchAuthor Commented:
Okay, I found it by viewing another solution and modifying the code a little bit:

e.Item.Cells[3].Text
0
 
chinu1310Commented:
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.
0
 
KaporchAuthor Commented:
I think your code might actually transfer the main page to another page, which is not what I want to do.
0
 
chinu1310Commented:
Ok now lets restart.
What you have and what you want to achieve ?
0
 
chinu1310Commented:
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 ?

0
 
KaporchAuthor Commented:
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!)
0
 
chinu1310Commented:
Thats good. Let us know if anything goes wrong.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 10
  • 8
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now