Querystring in Gridview HyperLinkField
-
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
-
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
hi,try this
-
hi,try this
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
-
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
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