Gridview - Reference to a new column

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2009
Posts: 5
Reputation: husna_ is an unknown quantity at this point 
Solved Threads: 0
husna_ husna_ is offline Offline
Newbie Poster

Gridview - Reference to a new column

 
0
  #1
Sep 15th, 2009
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"
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 66
Reputation: reach_yousuf is an unknown quantity at this point 
Solved Threads: 12
reach_yousuf reach_yousuf is offline Offline
Junior Poster in Training

Re: Gridview - Reference to a new column

 
0
  #2
Sep 16th, 2009
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
Yousuf
Software Developer
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 5
Reputation: husna_ is an unknown quantity at this point 
Solved Threads: 0
husna_ husna_ is offline Offline
Newbie Poster

Re: Gridview - Reference to a new column

 
0
  #3
Sep 16th, 2009
Hello. Can you please provide me with some example?
Reply With Quote Quick reply to this message  
Reply

Tags
c#gridviewcolumn

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC