Datagrid Push Button Link

I have a datagrid and I have added push buttons as a column. I also have a stored Procedure that runs and returns 2 fields. "Test_Name" and "URL" - I want to assign URL to the button so that when clicked the user is taken there
and the URL column is not shown
Any help is greatly appreciated
<div id="div1" align ="center">
        <p>These are the tests you can take</p>
        <asp:DataGrid id="DG" runat="server"  UseAccessibleHeader="True">
        <AlternatingItemStyle cssClass="GridAltRow" BackColor="#CCCCCC"></AlternatingItemStyle>
        <ItemStyle cssClass="GridRow"></ItemStyle>
        <Columns>
            <asp:ButtonColumn ButtonType="PushButton" HeaderText="Click to take the test" 
                Text="Take the test" CommandName="URL"></asp:ButtonColumn>
        </Columns>
        </asp:DataGrid>
        </div>

Open in new window

LVL 6
r3nderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

xizwyckCommented:
This might help as I haven't used a datagrid in a long while.

You could also try a ImageButton. You could even bind a url to it (from data - if the url is dynamic). But these two would need to be in an ItemTemplate.

<asp:HyperLInk ID="Hyperlink1" runat="server" NavigateUrl='<%# Bind("url") %>' ImageUrl="~/Images/myimage.png"/>

Yeah, it's not an imagebutton above but the concepts are similar.
<asp:DataList ID="DL_Exceptions" runat="server" DataKeyField="pkid" OnDeleteCommand="DL_Exceptions_DeleteCommand" Width="100%">
 <HeaderTemplate>
  <table border="0" cellpadding="0" cellspacing="0" style="width:100%">
   <tr>
    <td style="font-weight:bold">Associate</td>
    <td style="font-weight:bold;padding-left:10px">Change Reason</td>
    <td style="font-weight:bold;padding-left:10px">Date From/To</td>
    <td style="font-weight:bold;padding-left:10px">Copy?</td>
    <td style="font-weight:bold;padding-left:10px">Replace?</td>
    <td style="font-weight:bold;padding-left:10px">Mkt Appr?</td>
    <td style="font-weight:bold;padding-left:10px">Change Explanation</td>
    <td></td>
   </tr>
  </HeaderTemplate>
  <ItemTemplate>
   <tr>
    <td><asp:Label ID="L_AssociateName" runat="server" Text='<%# Eval("AssociateName") %>' /></td>
    <td style="padding-left:10px"><asp:Label ID="L_ReasonText" runat="server" Text='<%# Eval("ReasonText") %>' /></td>
    <td style="padding-left:10px">
     <asp:Label ID="L_SchDateFrom" runat="server" Text='<%# Eval("SchDateFrom","{0:MM/dd/yy}") %>' />&nbsp;-&nbsp;
     <asp:Label ID="L_SchDateTo" runat="server" Text='<%# Eval("SchDateTo","{0:MM/dd/yy}") %>' />
    </td>
    <td style="padding-left:10px"><asp:Label ID="L_CopySch" runat="server" Text='<%# Eval("Copy") %>'/></td>
    <td style="padding-left:10px"><asp:Label ID="L_Replacement" runat="server" Text='<%# Eval("Replace") %>'/></td>
    <td style="padding-left:10px"><asp:Label ID="L_MarketApproved" runat="server" Text='<%# Eval("Approved") %>'/></td>
    <td style="padding-left:10px"><asp:Label ID="L_ChangeExplanation" runat="server" Text='<%# Eval("ChangeExplanation") %>'/></td>
    <td style="padding-left:10px;text-align:right"><asp:LinkButton ID="LB_Delete" runat="server" Text="Delete" CommandName="Delete" CausesValidation="false"/></td>
    </tr>
    </ItemTemplate>
   <FooterTemplate>
  </table>
 </FooterTemplate>
</asp:DataList>


Code Behind:

        protected void DL_Exceptions_DeleteCommand(object sender, DataListCommandEventArgs e)
        {
            int id = Convert.ToInt32(DL_Exceptions.DataKeys[e.Item.ItemIndex]);

            using (SqlConnection SQLConnection = new SqlConnection())
            {
                SQLConnection.ConnectionString = ConfigurationManager.ConnectionStrings[Session["MSSQL"].ToString()].ConnectionString;
                SQLConnection.Open();
                SqlCommand SQLCmd = new SqlCommand("Delete From SCEExceptions Where pkid=@pkid", SQLConnection);
                SQLCmd.CommandType = CommandType.Text;
                SQLCmd.Parameters.AddWithValue("pkid", id);
                SQLCmd.ExecuteNonQuery();
            }

            DL_Exceptions.DataSource = QueueExceptions(TB_Uid.Text.ToString());
            DL_Exceptions.DataBind();

            if (DL_Exceptions.Items.Count == 0)
            {
                exceptions.Visible = false;
            }
        }

Open in new window

r3nderAuthor Commented:
xizwyck
Sorry- Neither examples worked :)
xizwyckCommented:
Could you expound? That sampling comes out of a working website.
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

r3nderAuthor Commented:
I am using a push button - to stay congruent with the site. - I guess I should have said I am using C# code behind
So I dont want to use an image button :)
xizwyckCommented:
I see. You can still use a push button but I've always had to use the ItemTemplate for good customization.

This http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.aspx shows more but you can use OnClientClick to call a Javascript function to redirect the user (i.e. window.navigate("somepage.aspx")) or CommandName = "Click" and then use OnItemCommand="RedirectUser", which would point to a c# method, or OnClick to use c# to redirect (Response.Redirect("somepage.aspx").
Obadiah ChristopherDeveloper User InterfaceCommented:
Adding to xizwyck's comment. Can't u use the LinkButton control in the ItemTemplate.
r3nderAuthor Commented:
Ok lets get back to what is needed
I need a way for a pushbutton to navigate to a URL - the URL is given in a stored procedure
I am binding those Items to a datagrid - I want the field URL not to show in the datagrid but be assigned to the push button - can anyone do that or does anyone have a viable sample.
I would really appreciate the help - thanks
r3nderAuthor Commented:
In addition I am adding how I am getting the information and binding it to the datagrid
try
           {
               con.Open();
               SqlCommand com = new SqlCommand("spx_availableTests", con);
               com.CommandType = CommandType.StoredProcedure;
               com.Parameters.Add("@UID",SqlDbType.Int).Value = UID;
               SqlDataAdapter adapter = new SqlDataAdapter(com);
               DataTable tbl = new DataTable();
               adapter.Fill(tbl);
               DG.DataSource = tbl;
               DG.DataBind();
               Response.Write(DG.Columns[1].ToString());
               

              con.Close();

           }

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
r3nderAuthor Commented:
The first link was what I was looking for - Thank you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.