Referencing cells in a nested gridview

Joined
Jul 4, 2007
Messages
3
Reaction score
0
Hi Folks

Can anyone tell me how I can reference cells in a nested gridview? I simply want a field where if the condition is "0/100", the field visibility does not display but the next cell with the value "Incomplete" is set to true. This is a grades nested gridview and I am under serious pressure to get this to work. I have used countless variations including setting up labels in a template field but nothing works. Please can anyone help I am at my wits end. Currently the cells that are being displayed are from the parent gridview. e.Row.Cells[0].Visible is having no effect on the gridview I want it to. Here is my code.

Code:
<%@ Control Language="C#" ClassName="mon_gradesb" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        BindData();
    }

    public void BindData()
    {
        string pattern = @"BELFASTMET\\|STUDENT\\";
        string user = HttpContext.Current.User.Identity.Name;
        user = Regex.Replace(user, pattern, "", RegexOptions.IgnoreCase);
        lblUser.Text = user;
    }


    protected void gvCars_rowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string pattern = @"*********\\|**********\\";
            string user = HttpContext.Current.User.Identity.Name;
            user = Regex.Replace(user, pattern, "", RegexOptions.IgnoreCase);
            lblUser.Text = user;
            GridView gv = (GridView)e.Row.FindControl("gvModels");
            String course = e.Row.Cells[0].Text;
            SqlConnection connUsers = new SqlConnection("Data Source=********\\********;Initial Catalog=*******;UID=**;password=*********;");
            //SqlConnection connUsers = new SqlConnection("Data Source=*********\\********;Initial Catalog=*******;UID=******;password=**********;");
            connUsers.Open();
            DataSet ds = new DataSet("my_grades");
            SqlCommand cmd = connUsers.CreateCommand();
            //cmd.Parameters.Add(new SqlParameter("@User", user));
            //cmd.Parameters.Add(new SqlParameter("@Course", course));
            cmd.CommandText = "SELECT * from my_grades where user_id='" + user + "' and COURSE_NAME ='" + course + "' order by type";
            
            //mon test
            //cmd.CommandText = "SELECT * from filter_one where user_id='mon01234567' and COURSE_NAME ='" + course + "' order by type";
            
            SqlDataAdapter da1 = new SqlDataAdapter(cmd.CommandText, connUsers);
            //SqlDataReader dr = cmd.ExecuteReader();
            da1.Fill(ds);
            gv.DataSource = ds;
            gv.DataBind();
            gv.Visible = true;
            connUsers.Close();
            for (int loop=0; loop<ds.Tables[0].Rows.Count; loop++ )
            {
                //string translate = ds.Tables[0].rows[loop]["ColName"].ToString();
                string translator = ds.Tables[0].Rows[loop]["grade_translator"].ToString();
                string actual = ds.Tables[0].Rows[loop]["Actual_Grade"].ToString();
                string manual = ds.Tables[0].Rows[loop]["manual_grade"].ToString();
                string mark = ds.Tables[0].Rows[loop]["mark"].ToString();
                //Response.Write(actual);
                //Response.Write(manual);
                //Response.Write(translator);
                //Response.Write(actual);
                //string test = actual + "<br />";
                //string test2 = translator + "<br />";
                string translatorText = translator + actual;
                string test3 = translatorText + "<br />";  
                //Response.Write(test);
                Response.Write(test3);
                string Final = "Complete/Incomplete0/100";
                string test4 = Final + "<br />";

                if (actual == "0/100")
                {
                    e.Row.Cells[0].Visible = false;
                    e.Row.Cells[1].Visible = true;

                    
                }
                else if (actual != "0/100")
                {
                    e.Row.Cells[0].Visible = false;
                    e.Row.Cells[1].Visible = true;
                }

            }
                    

        }
    }
    
</script>

<style type="text/css" id="Style1" runat="server">

.Grid { border: solid 1px #FFFFFF; font-family: Arial, sans-serif, "Franklin Gothic Book"; background-color="#FFFFFF"; }
.Grid td
{
	font-size: small;
	margin: 0px;
	padding: 0px;
	
}

.GridItem {
	color: #000000;
	font-weight: bolder;
	font-size: small;
	text-transform: uppercase;
	text-decoration: none;
	margin: 0px;
	padding-top: 0px;
	padding-right: 0px;
	padding-bottom: 5px;
	padding-left: 0px;
	padding: 0px;
	valign: top;
	line-spacing:1.25;
	
}




.GridTop
{

font-size: small;
margin: 0px;
padding: 0px;
color: #000000;

}



.style2 {
	text-align: center;
}

</style>


        <span class="style1"><strong><center>My Grades</center></strong></span>
        
        <asp:GridView ID="gvCars" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" DataKeyNames="COURSE_NAME" OnRowDataBound="gvCars_rowDataBound" CssClass="Grid" GridLines="None">
             <EmptyDataTemplate>
    <strong>This Feature is Coming Soon</strong>
  </EmptyDataTemplate>
            <Columns>
                <asp:BoundField DataField="COURSE_NAME"  SortExpression="COURSE_NAME"  itemStyle-font-bold="true">    
         </asp:BoundField> 
                 <asp:TemplateField>
                    <ItemTemplate><tr><td>&nbsp;
                        <asp:GridView ID="gvModels" runat="server" ShowHeader="False" SkinID="InnerGridView" AutoGenerateColumns="false" GridLines="None">
                        <Columns>
                <asp:BoundField DataField="title"  SortExpression="title"  itemStyle-font-bold="true" />    
                <asp:BoundField DataField="Actual_Grade"  SortExpression="Actual_Grade"  itemStyle-font-bold="true" />    
                 <asp:BoundField DataField="Incomplete"  SortExpression="Incomplete"  itemStyle-font-bold="true" Visible="true" />   
                        </Columns>
                        </asp:GridView><br /><br />
                    </ItemTemplate>
                </asp:TemplateField>
                
            </Columns>
            
        </asp:GridView>
        <br />
        <br />
        <asp:Label ID="lblUser" runat="server" Text="" Visible="false"></asp:Label>
        &nbsp;&nbsp;
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:connBB %>" SelectCommand="SELECT DISTINCT [COURSE_NAME] FROM [my_grades] WHERE user_id = @User">
<SelectParameters>
<asp:ControlParameter Name="User" ControlID="lblUser" />
</SelectParameters>
</asp:SqlDataSource>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top