Okies, If I check for null, i have to get the data from the database right?
For my project right now, i have 2 tables.
1) ModuleStrGrp - where all the details of all the staff teaching the modules, noOfHours etc.
2) ModuleStr - this states all the leaders of the modules together with other information.
So, right now, in the database, i wanted the new row column to indicate the leaders from the ModuleStr.
I have attach a print screen of the output
Although the row name is Module Leader, it shows the Staff.
The first name in the list indicates the Module leader. So, I want to show that the first name is a leader, whereas the rest is blank. (in the role column)
can you post your gridview markup, clearly showing which label you want to update?
also,in this line of code: if (row["ModuleLeader"].ToString() == "ModuleLeader")
we're comparing to a fixed string "ModuleLeader", will the database actually have values matching or equal to "ModuleLeader" for the column ModuleLeader??
can you give us an example of some values for column ModuleLeader? this is the column that you intend to use to set the "ML" indicator right?
Ohs, i see.
therefore, what the code means that the values must contain ModuleLeader right?
I changed one value for testing sake and add a staff called ModuleLeader, but same result, the role column did not come out anything.
I infer a staff is a Module Leader because in one of my table, "ModuleStr" it stores all the values for different modules the module leader.
And in another table, "ModuleStrGrp" it stores all the values for all the staffs teaching the same subject.
The role column is just to show out that if the column Module leaders (which all staff ID appears) have the staffID of a module leader (which is retrieve from another table), they will just indicate, "ML" in the role table.
husna_
Member
6 Points
44 Posts
Re: Gridview - Adding Columns
Sep 10, 2009 03:56 AM|LINK
Hello Peter,
Okies, If I check for null, i have to get the data from the database right?
For my project right now, i have 2 tables.
1) ModuleStrGrp - where all the details of all the staff teaching the modules, noOfHours etc.
2) ModuleStr - this states all the leaders of the modules together with other information.
So, right now, in the database, i wanted the new row column to indicate the leaders from the ModuleStr.
I have attach a print screen of the output
Although the row name is Module Leader, it shows the Staff.
The first name in the list indicates the Module leader. So, I want to show that the first name is a leader, whereas the rest is blank. (in the role column)
Thanks for your help.
Really appreciated it.
Husna
C# gridview column
PeteNet
All-Star
81342 Points
11398 Posts
Re: Gridview - Adding Columns
Sep 10, 2009 04:42 AM|LINK
not really....as you can see, it is right there with you as in: row["ModuleLeader"]
from what I can see in the image, it seems that the column ModuleLeader will always have values and so you're OK.
Just FYI, IF you had to, you could always have an additional check:
if (!DBNull.Value.Equals(row["ModuleLeader"]))
{
if (row["ModuleLeader"].ToString() == "ModuleLeader")
{
........
}
}
Peter
husna_
Member
6 Points
44 Posts
Re: Gridview - Adding Columns
Sep 10, 2009 04:58 AM|LINK
Hello peter,
Oh! I understand what you mean.
But, I still do not have the role showing out : (ML)
Husna
C# gridview column
PeteNet
All-Star
81342 Points
11398 Posts
Re: Gridview - Adding Columns
Sep 10, 2009 05:10 AM|LINK
are you updating the right label, is the Label ID 'Label1'??? :
Label lbl = e.Row.FindControl("Label1") as Label;
....and then step through in debug and see whether you do get lbl not equal to null
Peter
husna_
Member
6 Points
44 Posts
Re: Gridview - Adding Columns
Sep 10, 2009 05:35 AM|LINK
Hello peter,
yup. it is the right one.
even if i change the id name for it, doesnt show out.
Husna
PeteNet
All-Star
81342 Points
11398 Posts
Re: Gridview - Adding Columns
Sep 10, 2009 05:43 AM|LINK
can you post your gridview markup, clearly showing which label you want to update?
also,in this line of code: if (row["ModuleLeader"].ToString() == "ModuleLeader")
we're comparing to a fixed string "ModuleLeader", will the database actually have values matching or equal to "ModuleLeader" for the column ModuleLeader??
can you give us an example of some values for column ModuleLeader? this is the column that you intend to use to set the "ML" indicator right?
Peter
husna_
Member
6 Points
44 Posts
Re: Gridview - Adding Columns
Sep 10, 2009 06:16 AM|LINK
Gridview markup:
<asp:TemplateField HeaderText="Role"> <ItemTemplate> <asp:Label ID="lblRole" runat="server" Text="" /> </ItemTemplate> <HeaderStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="3px" /> <ItemStyle BorderColor="Black" BorderStyle="Solid" /> </asp:TemplateField>if (!DBNull.Value.Equals(row["ModuleLeader"])) { if (row["ModuleLeader"].ToString() == "ModuleLeader") { Label lbl = e.Row.FindControl("lblRole") as Label; if (lbl != null) { lbl.Text = "ML";Nope. there is no value called "ModuleLeader"
Sure. Some of the values for column "ModuleLeader" are:
C# gridview column
PeteNet
All-Star
81342 Points
11398 Posts
Re: Gridview - Adding Columns
Sep 10, 2009 06:31 AM|LINK
now you can see why I asked....the code execution will fail on this condition and won't go further to set up the Label:
if (row["ModuleLeader"].ToString() == "ModuleLeader")
as its never going to be equal to "ModuleLeader"!
This is your data; how else would you infer that a person is a Module Leader?
Can the Role column help? Are there going to be values in that column? Ideally the Role column would be the one to compare.
Peter
husna_
Member
6 Points
44 Posts
Re: Gridview - Adding Columns
Sep 10, 2009 07:06 AM|LINK
Ohs, i see.
therefore, what the code means that the values must contain ModuleLeader right?
I changed one value for testing sake and add a staff called ModuleLeader, but same result, the role column did not come out anything.
I infer a staff is a Module Leader because in one of my table, "ModuleStr" it stores all the values for different modules the module leader.
And in another table, "ModuleStrGrp" it stores all the values for all the staffs teaching the same subject.
The role column is just to show out that if the column Module leaders (which all staff ID appears) have the staffID of a module leader (which is retrieve from another table), they will just indicate, "ML" in the role table.
C# gridview column