943,587 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 798
  • ASP.NET RSS
Sep 15th, 2009
0

Gridview - Reference to a new column

Expand Post »
Hello. I have a gridview which takes in data from 3 tables. And this gridview also have an additional column called "Role" which is not included in the database. Currently, without adding any logic but simply using the findcontrol to the label, "Role", i can show out "ML" But, when I add in the logic, it did not appear at all.

In any case, does anyone knows how to insert "ML" into the "Role" column which is not found in the database but is reference from another column found in the database.

This is the codes used to display the "ML" in the role column.


protected void gridAMDisplay_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //find the Label control using FindControl and set its Text on some column value DataRowView row = (DataRowView)e.Row.DataItem;

        if (!DBNull.Value.Equals(row["ModuleLeader"]))
        {

            if (row["ModuleLeader"].ToString() == "ModuleStr")
            {
                Label lbl = e.Row.FindControl("lblRole") as Label;
                if (lbl != null)
                {
                    lbl.Text = "ML";
                }
            }
        }
    }
}

This part of the code when comment off, the ML can be displayed in the role column, otherwise, nothing is displayed. Therefore, i feel that the findcontrol part works. BUT, referencing does not works.

if (row["ModuleLeader"].ToString() == "ModuleStr") {...} As i mentioned, the role column was not included in any of the tables in the DB. Therefore, i added in this codes.

<asp:TemplateField HeaderText="Role">
                    <ItemTemplate>
                        <asp:Label ID="lblRole" runat="server" Text="" />
                    </ItemTemplate>
                </asp:TemplateField>

But, the problem i have now is, the role column does not reference to the column it is supposed to, which is "Module Leaders"
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
husna_ is offline Offline
5 posts
since Sep 2009
Sep 16th, 2009
0

Re: Gridview - Reference to a new column

Hi Husna

You can use Typed Dataset and merge the additional ROLE column to it, the dataset can be used to bind your GRIDVIEW and so on and so forth...

Regards
Reputation Points: 12
Solved Threads: 38
Junior Poster
reach_yousuf is offline Offline
194 posts
since Sep 2007
Sep 16th, 2009
0

Re: Gridview - Reference to a new column

Hello. Can you please provide me with some example?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
husna_ is offline Offline
5 posts
since Sep 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Dynamically creating dropdownlist
Next Thread in ASP.NET Forum Timeline: Learning Management System Final year project





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC