网格视图中的超链接在单击时不会在另一个页面中填充值 [英] hyperlink in grid view not populating values in another page when clicked

查看:53
本文介绍了网格视图中的超链接在单击时不会在另一个页面中填充值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,请帮我这个超链接的东西..我有一个网格视图,其中一列包含超链接说ViewDetails。在单击ViewDetails时,它应该导航到另一个名为Reports.aspx的页面,其中页面应在标签中的网格视图中显示选择列的网格行值。我已经使用了行数据绑定事件..如果我点击超链接我得到空白标签。我已经编写了存储过程来获取行值。我通过KEY调用它..它的TaskID是一个不可见的自动生成的列。取决于我需要显示行值的键值。



这里是代码



< pre lang =xml> < asp:GridView ID = GrdViewMyTasks runat = server AllowSorting = True

< span class =code-attribute> AutoGenerateColumns = False BackColor = 白色 < span class =code-attribute> BorderColor = #0061C1

BorderStyle = CaptionAlign = 底部 EmptyDataText = 未找到记录

字体名称 = Verdana 字体大小 = X-Small < span class =code-attribute> ForeColor = #0061C1

高度 = 179px OnRowDataBound = GrdViewMyTasks_RowDataBound

ShowFooter = True ShowHeaderWhenEmpty = True 宽度 = 99%

onselectedindexchanged = GrdViewMyTasks_SelectedIndexChanged

OnRowCreated = GrdViewMyTasks_RowCreated >

< >
< ; asp:BoundField DataField = < span class =code-keyword> TaskID HeaderText = SL否 可见 = False ReadOnly = True < span class =code-keyword>>
< FooterStyle BackColor = #0061C1 / >
< HeaderStyle BackColor = #0061C1 Horizo​​ntalAlign < span class =code-keyword> = 中心 VerticalAlign = 中间 / >
< ItemStyle Horizo​​ntalAlign = 中心 VerticalAlign = 中间 / >
< / asp:BoundField >
< asp:TemplateField HeaderText = 任务名称 >
< ItemTemplate >
< asp:标签 ID = TaskName runat = server

字体名称 = Verdana 字体大小 = X-Small 高度 = 24px

文本 =' < span class =code-pagedirective><% #Eval( TaskName%> ' 宽度 = 70px > < / asp:标签 >
< / ItemTemplate >
< FooterStyle BackColor = #0061C1 / >
< HeaderStyle BackColor = #0061C1 ForeColor = 白色 / >
< ItemStyle Horizo​​ntalAlign = 中心 VerticalAlign = 中间 / >
< / asp:TemplateField >
< asp:TemplateField HeaderText = 截止日期 >
< ItemTemplate >
< asp:标签 ID = DueDate runat = server 字体名称 = Verdana 字体大小 = X-Small

< span class =code-attribute> 高度 = 20px 宽度 = 70px 文本 =' <% #Eval( DueDate {0:dd / MM / yyyy}%> ' DataFormatString = {0:dd / MM / yyyy } > < / asp :标签 >
< / ItemTemplate >
< FooterStyle BackColor = #0061C1 / >
< HeaderStyle BackColor = #0061C1 ForeColor < span class =code-keyword> = 白色 / >
< ItemStyle Horizo​​ntalAlign = 中心 VerticalAlign = Mi ddle / >
< / asp:TemplateField > ;
< asp:TemplateField HeaderText = 描述 >
< ItemTemplate >
< asp:标签 ID = 描述 runat = 服务器 字体名称 = Verdana 字体大小 = X-Small 高度 = 20px 宽度 = 90px 文字 =' <% #Eval( < span class =code-string> Description%> ' > < / asp:Label >
< / ItemTemplate >
< FooterStyle BackColor = #0061C1 / >
< HeaderStyle BackColor = #0061C1 ForeColor = 白色 / >
< ItemStyle Horizo​​ntalAlign = VerticalAlign = 中间 / >
< / asp:TemplateField >

< asp:TemplateField HeaderText = 分配依据 >
< ItemTemplate >
< asp:标签 ID = AssignBy runat = server 字体名称 = Verdana 字体大小 = X-Small 高度 = 20px 宽度 = 90px 文字 =' <% #Eval( AssignBy%> ' > < / asp:标签 >
< / ItemTemplate >
< FooterStyle BackColor = #0061C1 / >
< HeaderStyle BackColor = #0061C1 ForeColor = 白色 / >
< ItemStyle Horizo​​ntalAlign = 中心 VerticalAlign = 中间 / >
< / asp:TemplateField >
< asp:TemplateField HeaderText = 状态 >
< ItemTemplate >
< asp:标签 ID = 状态 runat = server 字体名称 = Verdana 字体大小 = X-Small 高度 = 20px Width = 90px 文本 =' <% #Eval( 状态%> ' > < / asp:标签 >
< / ItemTemplate >
< FooterStyle BackColor = #0061C1 / >
< HeaderStyle BackColor = #0061C1 ForeColor = 白色 < span class =code-attribute> / >
< ItemStyle Horizo​​ntalAlign = 中心 VerticalAlign = 中间 / >
< / asp: TemplateField >
< asp:TemplateField HeaderText = %完成 >
< ItemTemplate >
< asp:Lab el ID = PercentageComplete\" runat=\"server\" Font-Names=\"Verdana\" Font-Size=\"X-Small \" Height=\" 20px\" Width=\"50px\" Text='<%# Eval(\"PercentageComplete\")%>'></asp:Label>
</ItemTemplate>
<FooterStyle BackColor=\"#0061C1\" />
<HeaderStyle BackColor=\"#0061C1\" ForeColor=\"White\" />
<ItemStyle HorizontalAlign=\"Center\" VerticalAlign=\"Middle\" />
</asp:TemplateField>
<asp:TemplateField HeaderText=\"View Details\">
<ItemTemplate>
<asp:HyperLink ID=\"ViewDetails\" runat=\"server\" Font-Names=\"Verdana\" Font-Size=\"X-Small\" Height=\"24px\" Width=\"70px\" ForeColor=\"#0061C1\" Text=\"ViewDetails\" NavigateUrl=\"Reports.aspx\">View</asp:HyperLink>
</ItemTemplate>
<FooterStyle BackColor=\"#0061C1\" />
<HeaderStyle BackColor=\"#0061C1\" ForeColor=\"White\" />
<ItemStyle HorizontalAlign=\"Center\" VerticalAlign=\"Middle\" />
</asp:TemplateField>
</Columns>
</asp:GridView>







aspx.cs code

protected void GrdViewMyTasks_RowDataBound(object sender, GridViewRowEventArgs e) 
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink ViewDetails = e.Row.FindControl(\"ViewDetails\") as HyperLink;
ViewDetails.NavigateUrl = \"Reports.aspx?TaskID=\" + e.Row.Cells[0].Text;
}
}







code in reports.aspx.cs

protected void Page_Load(object sender, EventArgs e) 
{
MTMSService obj = new MTMSService();
DBAccess db = new DBAccess();
{
MTMSDTO objc = new MTMSDTO();
{
int ID = 0;
int.TryParse(Request.QueryString[\"TaskID\"], out ID);
objc.TaskID = Convert.ToInt32(Request.QueryString[\"TaskID\"]);
DataSet rep = obj.GetReports();
DataView Rprts = new DataView();
Rprts.Table = rep.Tables[0];


var table = rep.Tables[0];

if (table.Rows.Count > 0)
{
LblTaskID.Text = rep.Tables[0].Rows[0][\"TaskID\"].ToString();
LblTaskName.Text = rep.Tables[0].Rows[0][\"TaskName\"].ToString();
LblDueDate.Text = rep.Tables[0].Rows[0][\"DueDate\"].ToString();
LblDescription.Text = rep.Tables[0].Rows[0][\"Description\"].ToString();
LblAssignBy.Text = rep.Tables[0].Rows[0][\"AssignBy\"].ToString();
LblStatus.Text = rep.Tables[0].Rows[0][\"Status\"].ToString();
LblPercentageComplete.Text = rep.Tables[0].Rows[0][\"PercentageComplete\"].ToString();
}

else
{

}


LblTaskName.Visible = true;
LblAssignBy.Visible = true;
LblDescription.Visible = true;
LblDueDate.Visible = true;
LblStatus.Visible = true;
LblPercentageComplete.Visible = true;
LblAssignTo.Visible = false;
}
}
}





and this is my stored procedure 

<pre lang=\"sql\">ALTER PROCEDURE [dbo].[GetReports]

@TaskID int

AS

Select TaskName, DueDate, Description, AssignBy, Status, PercentageComplete, TaskID

From dbo.Task

Where TaskID = @TaskID;</pre>

解决方案

I think if you pass TaskID then you have to use querystrig here ...

I dont unserstand how can you get values in session



YOu can use Querystring as below...



int ID=0; 
int.TryParse(Request.QueryString[\"TaskID\"], out ID);







then by this ID you can retrieve data from database with sp.


<asp:hyperlink id=\"ViewDetails\" runat=\"server\" font-names=\"Verdana\" font-size=\"X-Small\" height=\"24px\" width=\"70px\" forecolor=\"#0061C1\" text=\"ViewDetails\" navigateurl=\"<%# \" ~=\"\" incidentreports.aspx?taskid=\" + Eval(\" taskid\").tostring()=\"\" %&gt;\"=\"\" xmlns:asp=\"#unknown\">


Hello ,please help me with this hyperlink thing.. i got a grid view where one of the column contains hyperlink say ViewDetails. upon clicking ViewDetails it should get navigate to another page called as Reports.aspx where the page should display the grid row value of selectd column in grid view in labels. i have used row data bound event .. im getting blank labels if i click the hyperlink . i have written stored procedure to get the row values. and im calling it through KEY.. its TaskID which is an auto generated column which is invisible. depending on the key value i need to display the row values.

here are the codes

<asp:GridView ID="GrdViewMyTasks" runat="server" AllowSorting="True"

           AutoGenerateColumns="False" BackColor="White" BorderColor="#0061C1"

           BorderStyle="None" CaptionAlign="Bottom" EmptyDataText="No Records Found"

           Font-Names="Verdana" Font-Size="X-Small" ForeColor="#0061C1"

           Height="179px" OnRowDataBound="GrdViewMyTasks_RowDataBound"

           ShowFooter="True" ShowHeaderWhenEmpty="True" Width="99%"

           onselectedindexchanged="GrdViewMyTasks_SelectedIndexChanged"

           OnRowCreated="GrdViewMyTasks_RowCreated" >

             <Columns>
             <asp:BoundField DataField="TaskID" HeaderText="SL No" Visible="False" ReadOnly="True">
          <FooterStyle BackColor="#0061C1" />
          <HeaderStyle BackColor="#0061C1" HorizontalAlign="Center" VerticalAlign="Middle" />
          <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
          </asp:BoundField>
          <asp:TemplateField HeaderText="Task Name">
          <ItemTemplate>
          <asp:Label ID="TaskName" runat="server"

          Font-Names="Verdana" Font-Size="X-Small" Height="24px"

          Text='<%# Eval("TaskName")%>' Width="70px"></asp:Label>
          </ItemTemplate>
          <FooterStyle BackColor="#0061C1" />
          <HeaderStyle BackColor="#0061C1" ForeColor="White" />
          <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
          </asp:TemplateField>
          <asp:TemplateField HeaderText="Due Date">
          <ItemTemplate>
          <asp:Label ID="DueDate" runat="server" Font-Names="Verdana" Font-Size="X-Small"

          Height="20px" Width="70px" Text='<%# Eval("DueDate","{0:dd/MM/yyyy}")%>' DataFormatString="{0:dd/MM/yyyy}"></asp:Label>
          </ItemTemplate>
          <FooterStyle BackColor="#0061C1" />
          <HeaderStyle BackColor="#0061C1" ForeColor="White" />
          <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
          </asp:TemplateField>
          <asp:TemplateField HeaderText="Description">
          <ItemTemplate>
          <asp:Label ID="Description" runat="server" Font-Names="Verdana" Font-Size="X-Small" Height="20px" Width="90px" Text='<%# Eval("Description")%>'></asp:Label>
          </ItemTemplate>
          <FooterStyle BackColor="#0061C1" />
          <HeaderStyle BackColor="#0061C1" ForeColor="White" />
          <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" />
          </asp:TemplateField>
          <asp:TemplateField HeaderText="Assign By">
          <ItemTemplate>
          <asp:Label ID="AssignBy" runat="server" Font-Names="Verdana" Font-Size="X-Small" Height="20px" Width="90px" Text='<%# Eval("AssignBy")%>'></asp:Label>
          </ItemTemplate>
          <FooterStyle BackColor="#0061C1" />
          <HeaderStyle BackColor="#0061C1" ForeColor="White" />
          <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
          </asp:TemplateField>
          <asp:TemplateField HeaderText="Status">
          <ItemTemplate>
          <asp:Label ID="Status" runat="server" Font-Names="Verdana" Font-Size="X-Small" Height="20px" Width="90px" Text='<%# Eval("Status")%>'></asp:Label>
          </ItemTemplate>
          <FooterStyle BackColor="#0061C1" />
          <HeaderStyle BackColor="#0061C1" ForeColor="White" />
          <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
          </asp:TemplateField>
          <asp:TemplateField HeaderText="% Complete">
          <ItemTemplate>
          <asp:Label ID="PercentageComplete" runat="server" Font-Names="Verdana" Font-Size="X-Small" Height="20px" Width="50px" Text='<%# Eval("PercentageComplete")%>'></asp:Label>
          </ItemTemplate>
          <FooterStyle BackColor="#0061C1" />
          <HeaderStyle BackColor="#0061C1" ForeColor="White" />
          <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
          </asp:TemplateField>
          <asp:TemplateField HeaderText="View Details">
          <ItemTemplate>
          <asp:HyperLink ID="ViewDetails" runat="server" Font-Names="Verdana" Font-Size="X-Small" Height="24px" Width="70px" ForeColor="#0061C1" Text="ViewDetails" NavigateUrl="Reports.aspx">View</asp:HyperLink>
          </ItemTemplate>
          <FooterStyle BackColor="#0061C1" />
          <HeaderStyle BackColor="#0061C1" ForeColor="White" />
          <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
        </asp:TemplateField>
        </Columns>
     </asp:GridView>




aspx.cs code

protected void GrdViewMyTasks_RowDataBound(object sender, GridViewRowEventArgs e)
   {
       if (e.Row.RowType == DataControlRowType.DataRow)
       {
           HyperLink ViewDetails = e.Row.FindControl("ViewDetails") as HyperLink;
           ViewDetails.NavigateUrl = "Reports.aspx?TaskID=" + e.Row.Cells[0].Text;
       }
   }




code in reports.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
MTMSService obj = new MTMSService();
DBAccess db = new DBAccess();
{
MTMSDTO objc = new MTMSDTO();
{
 int ID = 0;
 int.TryParse(Request.QueryString["TaskID"], out ID);
objc.TaskID = Convert.ToInt32(Request.QueryString["TaskID"]);
DataSet rep = obj.GetReports();
DataView Rprts = new DataView();
Rprts.Table = rep.Tables[0];


var table = rep.Tables[0];

if (table.Rows.Count > 0)
{
LblTaskID.Text = rep.Tables[0].Rows[0]["TaskID"].ToString();
LblTaskName.Text = rep.Tables[0].Rows[0]["TaskName"].ToString();
LblDueDate.Text = rep.Tables[0].Rows[0]["DueDate"].ToString();
LblDescription.Text = rep.Tables[0].Rows[0]["Description"].ToString();
LblAssignBy.Text = rep.Tables[0].Rows[0]["AssignBy"].ToString();
LblStatus.Text = rep.Tables[0].Rows[0]["Status"].ToString();
LblPercentageComplete.Text = rep.Tables[0].Rows[0]["PercentageComplete"].ToString();
}

else
{

}


LblTaskName.Visible = true;
LblAssignBy.Visible = true;
LblDescription.Visible = true;
LblDueDate.Visible = true;
LblStatus.Visible = true;
LblPercentageComplete.Visible = true;
LblAssignTo.Visible = false;
}
}
}



and this is my stored procedure

<pre lang="sql">ALTER PROCEDURE [dbo].[GetReports]

        @TaskID int

        AS

        Select TaskName, DueDate, Description, AssignBy, Status, PercentageComplete, TaskID

        From dbo.Task

        Where TaskID = @TaskID;</pre>

解决方案

I think if you pass TaskID then you have to use querystrig here ...
I dont unserstand how can you get values in session

YOu can use Querystring as below...

int ID=0;
int.TryParse(Request.QueryString["TaskID"], out ID);




then by this ID you can retrieve data from database with sp.


<asp:hyperlink id="ViewDetails" runat="server" font-names="Verdana" font-size="X-Small" height="24px" width="70px" forecolor="#0061C1" text="ViewDetails" navigateurl="<%# " ~="" incidentreports.aspx?taskid=" + Eval(" taskid").tostring()="" %&gt;"="" xmlns:asp="#unknown">


这篇关于网格视图中的超链接在单击时不会在另一个页面中填充值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆