redirecting from grid
redirecting from grid
redirecting from grid
redirecting from grid
redirecting from grid
redirecting from grid redirecting from grid redirecting from grid redirecting from grid redirecting from grid redirecting from grid redirecting from grid redirecting from grid
redirecting from grid redirecting from grid
redirecting from grid
Go Back  Xtreme Visual Basic Talk > > > redirecting from grid


Reply
 
Thread Tools Display Modes
  #1  
Old 08-24-2012, 09:51 AM
torpkevuk's Avatar
torpkevuk torpkevuk is offline
Contributor
 
Join Date: Oct 2003
Location: Nebraska, USA
Posts: 640
Default redirecting from grid


Hi all..

I have some data coming from a database which I want to display in a grid, which is fairly simple, but I'm running into some issues.

I have data coming like:

functionname | functionicon | functionid
UM | ~/icons/um.png | 1
SM | ~/icons/sm.png | 2

In my grid, I want to display the icon (which is the URL to an image) with the name as a tooltip and the function id being passed as a parameter so I know what I'm doing.

To make things more interesting I wanted to put each row into the grid side by side up to 5 across

func01 | func02 | func03 | func04 | func05
func06 | func07 | func08 | func09 | func10
func11 | func12 | func13 | func14 | func15

I managed all this - I created a gridview and use an asp imagebutton for the icon - then loop through my result set and put each row into the next column until it reaches 5th one along then into the next row.. not beautiful code, but works.

The problem I'm having though is that when I click on the functions icon - it looks up a URL based on the function id - I then do a response.redirect - but instead of taking me to the page returned from my lookup, its taking me back to the same page.

Here's my grid view

Code:
<asp:GridView ID="gvAppFunctions" Runat="server" AutoGenerateColumns="False" BorderWidth="1px" BackColor="White" 
    CellPadding="3" BorderStyle="None" BorderColor="#CCCCCC" Font-Names="Arial" EnableTheming="True" style="text-align: center">
<FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
<PagerStyle ForeColor="#000066" HorizontalAlign="Left" BackColor="White"></PagerStyle>
<HeaderStyle ForeColor="White" Font-Bold="True" BackColor="#006699"></HeaderStyle>
<Columns>

    <asp:TemplateField HeaderStyle-Width="40">
        <ItemTemplate>
            <asp:ImageButton ID="AppLogo1" runat="server" ImageUrl='<%# Eval("funciconcol1") %>' OnClick="LogoClick_Click" 
                ToolTip= '<%# Eval("funcnamecol1") %>' CommandArgument='<%# Eval("appfuncidcol1") %>'/>
            <br /><asp:Label ID="lblApp1" runat="server" Text='<%# Eval("funcnamecol1") %>' Font-Size="Small"/>
        </ItemTemplate>
        <HeaderStyle Width="40px"></HeaderStyle>
    </asp:TemplateField>

    <asp:TemplateField HeaderStyle-Width="40">
        <ItemTemplate>
            <asp:ImageButton ID="AppLogo2" runat="server" ImageUrl='<%# Eval("funciconcol2") %>' OnClick="LogoClick_Click" 
                ToolTip= '<%# Eval("funcnamecol2") %>' CommandArgument='<%# Eval("appfuncidcol2") %>'/>
            <br /><asp:Label ID="lblApp2" runat="server" Text='<%# Eval("funcnamecol2") %>' Font-Size="Small"/>
        </ItemTemplate>
        <HeaderStyle Width="40px"></HeaderStyle>
    </asp:TemplateField>

    <asp:TemplateField HeaderStyle-Width="40">
        <ItemTemplate>
            <asp:ImageButton ID="AppLogo3" runat="server" ImageUrl='<%# Eval("funciconcol3") %>' OnClick="LogoClick_Click" 
                ToolTip= '<%# Eval("funcnamecol3") %>' CommandArgument='<%# Eval("appfuncidcol3") %>'/>
            <br /><asp:Label ID="lblApp3" runat="server" Text='<%# Eval("funcnamecol3") %>' Font-Size="Small"/>
        </ItemTemplate>
        <HeaderStyle Width="40px"></HeaderStyle>
    </asp:TemplateField>

    <asp:TemplateField HeaderStyle-Width="40">
        <ItemTemplate>
            <asp:ImageButton ID="AppLogo4" runat="server" ImageUrl='<%# Eval("funciconcol4") %>' OnClick="LogoClick_Click" 
                ToolTip= '<%# Eval("funcnamecol4") %>' CommandArgument='<%# Eval("appfuncidcol4") %>'/>
            <br /><asp:Label ID="lblApp4" runat="server" Text='<%# Eval("funcnamecol4") %>' Font-Size="Small"/>
        </ItemTemplate>
        <HeaderStyle Width="40px"></HeaderStyle>
    </asp:TemplateField>

    <asp:TemplateField HeaderStyle-Width="40">
        <ItemTemplate>
            <asp:ImageButton ID="AppLogo5" runat="server" ImageUrl='<%# Eval("funciconcol5") %>' OnClick="LogoClick_Click" 
                ToolTip= '<%# Eval("funcnamecol5") %>' CommandArgument='<%# Eval("appfuncidcol5") %>'/>
            <br /><asp:Label ID="lblApp5" runat="server" Text='<%# Eval("funcnamecol5") %>' Font-Size="Small"/>
        </ItemTemplate>
        <HeaderStyle Width="40px"></HeaderStyle>
    </asp:TemplateField>

</Columns>
<SelectedRowStyle ForeColor="White" Font-Bold="True" BackColor="#669999"></SelectedRowStyle>
<RowStyle ForeColor="#000066"></RowStyle>
</asp:GridView>
Now - as you can see, the OnClick leads me to LogoClick_Click

Code:
protected void LogoClick_Click(object sender, EventArgs e)
        {
            ImageButton clickedButton = sender as ImageButton;
            int appfunctionid = Convert.ToInt32(clickedButton.CommandArgument.ToString());
            if (appfunctionid != -1)
            {
                string functionurl = getStudyFunctionURL(Convert.ToInt32(mysession.Current.selected_study.ToString()), appfunctionid);
                Response.Redirect(functionurl);
            }
        }
I've checked by stepping through.. functionurl is returning something like 'http://localhost/UM/default.aspx'

It runs the Response Redirect step but the page I'm running it from is the one that reloads.

Can anyone shed any light on what I'm doing wrong here?

Thanks


EDIT: If it makes life easier - i can pass the URL during the initial data load - its really not that big a deal - just didn't to save on how much data is coming back from the db - but for this page.. I can live with the additional load as I know roughly how many results I'll return here.
Reply With Quote
  #2  
Old 08-24-2012, 12:39 PM
torpkevuk's Avatar
torpkevuk torpkevuk is offline
Contributor
 
Join Date: Oct 2003
Location: Nebraska, USA
Posts: 640
Default

I've worked this out..

Figured I was using a square peg in a round hole.. in this case.. a gridview where a simple asp Table would suffice

Code:
<asp:Table ID="tbl" runat="server" /></p>
And here's my code.. (dtFA is my datatable)

Code:
 if (dtFA.Rows.Count == 0)
            {
                tbl.Visible = false;
            }

            int xpos = 0;
            TableRow rowNew = new TableRow();
            foreach (DataRow drFA in dtFA.Rows)
            {
                TableCell cellNew = new TableCell();
                cellNew.Width = 95;
                cellNew.Height = 120;
                cellNew.HorizontalAlign = HorizontalAlign.Center;
                xpos += 1;
                if (xpos > 5)
                {
                    // Keep the grid 5 columns wide
                    xpos = 1;
                    tbl.Controls.Add(rowNew);
                    rowNew = new TableRow();
                }
                rowNew.Cells.Add(cellNew);
                ImageButton imgNew = new ImageButton();
                imgNew.ImageUrl = drFA["functionicon"].ToString();
                imgNew.PostBackUrl = drFA["studyfunctionurl"].ToString();
                imgNew.ToolTip = drFA["functionname"].ToString();
                Label lblNew = new Label();
                lblNew.Text = "<br />" + drFA["functionname"].ToString();
                cellNew.Controls.Add(imgNew);
                cellNew.Controls.Add(lblNew);
            }
            tbl.Controls.Add(rowNew);
Just added my URL to my initial data lookup and got rid of the onclick code all together

Thanks anyway folks!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
redirecting from grid
redirecting from grid
redirecting from grid redirecting from grid
redirecting from grid
redirecting from grid
redirecting from grid redirecting from grid redirecting from grid redirecting from grid redirecting from grid redirecting from grid redirecting from grid
redirecting from grid
redirecting from grid
 
redirecting from grid
redirecting from grid
 
-->