Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Querystring in Gridview HyperLinkField

Querystring in Gridview HyperLinkField

Scheduled Pinned Locked Moved ASP.NET
csharpdesignhelptutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Humayun Shabbir
    wrote on last edited by
    #1

    I want to have current querystring values in HyperLinkField of a Gridview. For example i have a list of employees page with department id already in the querystring, now i want to have View Details link to take user to employee details page with employee_id added to querystring but also keep department_id in the querystring. Like following code

    <asp:HyperLinkField DataNavigateUrlFields="employee_id, <%= Request.Querystring["department_id"] %>"
    DataNavigateUrlFormatString="employee_details.aspx?employee_id={0}&department_id{1}" HeaderText="Action" Text="View Details" />

    The current code gives me following error message.

    Parser Error Message: Literal content ('<asp:HyperLinkField DataNavigateUrlFields="candidate_id,') is not allowed within a 'System.Web.UI.WebControls.DataControlFieldCollection'.

    I hope there is some other way i can achieve this functionality while keeping it declarative as possible without using code behind. Thanks

    Humayun Shabbir Bhutta http://www.sourcesystems.net http://sourcesystems.net/humayun

    S L 2 Replies Last reply
    0
    • H Humayun Shabbir

      I want to have current querystring values in HyperLinkField of a Gridview. For example i have a list of employees page with department id already in the querystring, now i want to have View Details link to take user to employee details page with employee_id added to querystring but also keep department_id in the querystring. Like following code

      <asp:HyperLinkField DataNavigateUrlFields="employee_id, <%= Request.Querystring["department_id"] %>"
      DataNavigateUrlFormatString="employee_details.aspx?employee_id={0}&department_id{1}" HeaderText="Action" Text="View Details" />

      The current code gives me following error message.

      Parser Error Message: Literal content ('<asp:HyperLinkField DataNavigateUrlFields="candidate_id,') is not allowed within a 'System.Web.UI.WebControls.DataControlFieldCollection'.

      I hope there is some other way i can achieve this functionality while keeping it declarative as possible without using code behind. Thanks

      Humayun Shabbir Bhutta http://www.sourcesystems.net http://sourcesystems.net/humayun

      S Offline
      S Offline
      SunithaNallana
      wrote on last edited by
      #2

      hi,try this

      H 1 Reply Last reply
      0
      • S SunithaNallana

        hi,try this

        H Offline
        H Offline
        Humayun Shabbir
        wrote on last edited by
        #3

        Hi, i was also able to resolve this problem by converting the field to template using following code. And without going to codebehind :)

                        <asp:TemplateField HeaderText="Action">
                            <ItemTemplate>
                                <asp:HyperLink ID="HyperLink1" runat="server" 
                                    NavigateUrl='<%# Eval("employee\_id", "employee\_details.aspx?cid={0}&department\_id=" + Request.QueryString\["department\_id"\]) %>'
                                    Text="View Details"></asp:HyperLink>
                            </ItemTemplate>
                        </asp:TemplateField>
        

        Humayun Shabbir Bhutta http://www.sourcesystems.net http://sourcesystems.net/humayun

        1 Reply Last reply
        0
        • H Humayun Shabbir

          I want to have current querystring values in HyperLinkField of a Gridview. For example i have a list of employees page with department id already in the querystring, now i want to have View Details link to take user to employee details page with employee_id added to querystring but also keep department_id in the querystring. Like following code

          <asp:HyperLinkField DataNavigateUrlFields="employee_id, <%= Request.Querystring["department_id"] %>"
          DataNavigateUrlFormatString="employee_details.aspx?employee_id={0}&department_id{1}" HeaderText="Action" Text="View Details" />

          The current code gives me following error message.

          Parser Error Message: Literal content ('<asp:HyperLinkField DataNavigateUrlFields="candidate_id,') is not allowed within a 'System.Web.UI.WebControls.DataControlFieldCollection'.

          I hope there is some other way i can achieve this functionality while keeping it declarative as possible without using code behind. Thanks

          Humayun Shabbir Bhutta http://www.sourcesystems.net http://sourcesystems.net/humayun

          L Offline
          L Offline
          Linda1st
          wrote on last edited by
          #4

          It work out best for me by set the gridView at runtime... protected void Page_Load(object sender, EventArgs e) { grid1.Visible = true; setGridValues(); } private void setGridValues() { grid1.Visible = true; grid1.AutoGenerateColumns = true; DataTable dt = new DataTable(); // dataTable // column names ... dt.Columns.Add("ID"); dt.Columns.Add("DateRequested"); dt.Columns.Add("ServicePartNo"); dt.Columns.Add("qty."); dt.Columns.Add("VIN"); dt.Columns.Add("RoNo"); dt.Columns.Add("GCQIS"); dt.Columns.Add("Status"); // add hyper link to add to grid1........................ HyperLinkField linkX = new HyperLinkField(); string[] fldS = { "ID","Status" }; linkX.HeaderText = "ReqID"; linkX.DataTextField = "ID"; linkX.DataNavigateUrlFields = fldS; linkX.DataNavigateUrlFormatString = "summaryReqNo.aspx?reqNo={0}&status={1}"; linkX.Target = "_self"; // = "_blank" grid1.Attributes.Add("BackColor", "#CCCCCC"); // add attributes to grid grid1.Attributes.Add( "BorderColor", "#000099"); grid1.Attributes.Add("BorderWidth", "3px"); grid1.Attributes.Add("ForeColor","#333399"); grid1.Attributes.Add("Width", "7in"); grid1.Columns.Add(linkX); // adding hyper link devined above to grid cRequests reqS = new cRequests(userX); // values from classto loade into grid // adding rows to grid1 ...................................... foreach (cRequest item in reqS) { object[] aryX = new object[8]; aryX[0] = (item.reqID); aryX[1] = (item.reqDate).Value.ToShortDateString(); aryX[2] = (svcPN.prefix) + "-" + (svcPN.basePart) + "-" + (svcPN.suffix); aryX[3] = (svcPN.svcQty); aryX[4] = (item.reqVIN); aryX[5] = (item.reqOrdNo); aryX[6] = (item.reqGCQISNo); aryX[7] = item.status; dt.Rows.Add(aryX); } grid1.DataSource = dt; grid1.DataBind(); // gridX.DataSource = arryLstX; } I hopes this helps. Thanks, Signed Lindall

          xxx

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups