views:

326

answers:

4

How do you retrieve the URL for a discussion board item? That is, the URL displayed when you mouse over the subject line (once the list has been added to the page as a web part).

A: 

Are you asking how to find the URL for an individual discussion in a discussion board? Or an individual reply to a discussion?

elorg
A: 

You can give just subject name like http://site/discussion/lists/discussionboard/discusontitlename or subject

jain
A: 

protected void gvForum_RowDataBound(object sender, GridViewRowEventArgs e) { SPListItem item = e.Row.DataItem as SPListItem; Label lblTitle = e.Row.FindControl("lblTitle") as Label; HtmlAnchor aURL = e.Row.FindControl("aURL") as HtmlAnchor; if (item != null) { if (lblTitle != null && aURL != null) { aURL.HRef = "~/" + item.Url; lblTitle.Text = item["Title"].ToString();

            }
        }
    }
yarik
A: 
    protected global::System.Web.UI.WebControls.GridView gvForum;
    public string Region
    {
        get
        {
            return "";
        }
    }
    public string DefaultRegion { get; set; }
    public int Top { get; set; }
    public string ListName
    {
        get
        {

            string listName=string.Empty;
            if (!string.IsNullOrEmpty(this.Region))
                listName=string.Format("{0} {1}","Forum",this.Region);
            else
                listName = string.Format("{0} {1}", "Forum", this.DefaultRegion);
            return listName;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGrid();
        }
    }

    private void BindGrid()
    {
        string region = this.Region;
        string caml=@"<OrderBy><FieldRef Name=""Modified"" /></OrderBy>";
        try
        {
            using (SPSite spSite = new SPSite(SPContext.Current.Site.Url))
            {
                using (SPWeb spWeb = spSite.OpenWeb())
                {
                    SPQuery spQ = new SPQuery();
                    spQ.Query = caml;
                    spQ.RowLimit = (uint)this.Top;
                    SPList spList = spWeb.Lists[ListName];
                    SPListItemCollection items = spList.GetItems(spQ);
                    if (items != null && items.Count > 0)
                    {
                        gvForum.DataSource = items;
                        gvForum.DataBind();
                    }
                    else
                    {
                        this.Visible = false;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Logger.Log(ex.Message, System.Diagnostics.EventLogEntryType.Error);
        }

    }
    protected void gvForum_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        SPListItem item = e.Row.DataItem as SPListItem;
        Label lblTitle = e.Row.FindControl("lblTitle") as Label;
        HtmlAnchor aURL = e.Row.FindControl("aURL") as HtmlAnchor;
        if (item != null)
        {
            if (lblTitle != null && aURL != null)
            {
                aURL.HRef = "~/" + item.Url;
                lblTitle.Text = item["Title"].ToString();


            }
        }
    }
yarik