I have a webpage where a student or teacher can check their information. The way it works is that first they enter in their ID and the webpage evaluates the ID and finds information related to that ID. Than the student or teacher can click on their ID and than it supposed to check if it's a teacher or student depending on that it should navigate to the appropriate page. I was thinking that can be done in Page_Load method.
The difference between the Student ID and Teacher ID is that StudentID is less than 6 character and TeacherID is longer than 6 character.
Currently in the Default.aspx page it has this which only goes to the TeacherData.aspx page but it is not linked to the StudentData.aspx page.
ID |
Text='<%# Eval("UserID") %>'> |
Above part Evaluates the ID and finds the information from the sql table.
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsCallback)
{ //if it's student than go to this hyperlink instead // HyperLink1.NavigateUrl }
}
}
How do I write the function to change the hyperlink if it's a student? Please help, thank you in advance.
Abhay ShankerRank #375 · 6.7K reputationPosted Jan 15, 2014, 6:49 PM EST
NavigateUrl='<%# "~/Identification/TeacherData.aspx?ID="+Eval("ID")
That's Why you are redirected to teacher .aspx
You should modify the code and on click event of Link button Check condition and redirect to required page
It can be also achieved by Javascript
Biswa Pujarini MohapatraRank #465 · 5.4K reputationPosted Jan 15, 2014, 11:46 PM EST
Change you code as below
remove Navigate URL from aspx page of hyperlink
use Gridview row databound
ex:
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink myHL = (HyperLink)e.Row.FindControl("HyperLink1");
if("students")//Write your condition
myHL.NavigateUrl = "StudentsData.Aspx?id=" + e.Row.Cells[0].Text.ToString();// Change the cell index accordingly
else
myHL.NavigateUrl = "TeachersData.Aspx?id=" + e.Row.Cells[0].Text.ToString();// Change the cell index accordingly
}
}
kaurm11 reputationPosted Jan 16, 2014, 8:48 AM EST
Biswa Pujarini MohapatraRank #465 · 5.4K reputationPosted Jan 16, 2014, 4:36 PM EST
kaurm11 reputationPosted Jan 20, 2014, 9:16 AM EST
Navigate url to NavigateUrl='<%# switchTestDataPageMethod(Eval("ID")) %>'
than wrote a method that would check the ID and switch the pages. Thank you for your help.