Referencing cells in a nested gridview

Discussion in '.NET' started by Indo77, Oct 8, 2007.

  1. Indo77

    Indo77

    Joined:
    Jul 4, 2007
    Messages:
    3
    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>
    
    
     
    Indo77, Oct 8, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SixStringSlaya@gmail.com
    Replies:
    0
    Views:
    559
    SixStringSlaya@gmail.com
    Feb 28, 2006
  2. Ole Streicher
    Replies:
    3
    Views:
    2,917
    Ole Streicher
    Apr 11, 2008
  3. Nitz
    Replies:
    1
    Views:
    1,035
    Sam Evans
    Apr 6, 2009
  4. Joel Finkel

    Cells[].Text or Cells[].Controls[0]

    Joel Finkel, Sep 1, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    343
    Joel Finkel
    Sep 1, 2003
  5. Chris New

    Accessing Table Cells Within Nested Frames

    Chris New, Jul 13, 2003, in forum: Javascript
    Replies:
    2
    Views:
    203
Loading...

Share This Page