Click here to Skip to main content
15,886,075 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
here is my code

protected void Search_Click(object sender, ImageClickEventArgs e)
   {

       //grdTimeTable.Rows.Clear();
       grdTimeTable.ColumnCount = 10;
      grdTimeTable.RowCount = 10;
      grdTimeTable.Columns[0].Width = 100;
      grdTimeTable.Columns[1].Width = 100;
      grdTimeTable.Columns[2].Width = 20;
      grdTimeTable.Columns[3].Width = 100;
      grdTimeTable.Columns[4].Width = 100;
      grdTimeTable.Columns[5].Width = 20;
      grdTimeTable.Columns[6].Width = 100;
      grdTimeTable.Columns[7].Width = 100;
       //grdTimeTable.Rows(0).Cells(0).Value = "Semister";
       grdTimeTable.Columns[0].HeaderText = "I Row";
       grdTimeTable.Columns[1].HeaderText = "II Row";
       grdTimeTable.Columns[2].HeaderText = "";
       grdTimeTable.Columns[3].HeaderText = "III Row";
       grdTimeTable.Columns[4].HeaderText = "IV Row";
       grdTimeTable.Columns[5].HeaderText = "";
       grdTimeTable.Columns[6].HeaderText = "V Row";
       grdTimeTable.Columns[7].HeaderText = "VI Row";

       int a = 1, b = 0, c = 0;
       DateTime d1 = DateTime.Today.Date;
       string str1 = "";
       str1 = ddlSemister.SelectedValue;
       d1 = new DateTime(int.Parse(str1.Substring(6, 4)), int.Parse(str1.Substring(3, 2)), int.Parse(str1.Substring(0, 2)));

       if (conn.State == ConnectionState.Open) { conn.Close(); }
       conn.Open();
       SqlCommand cmd = new SqlCommand();
       SqlDataReader dr;
       cmd.Connection = conn;
       cmd.CommandText = "select Regno,deskno,deskside,semister from AllotmentTab where RoomNo='" + ddlSemister.SelectedValue + "' and examdate='" + d1 + "' and esession='" + ddlSession.SelectedValue + "'  order by Deskno,deskside";
       dr = cmd.ExecuteReader();
       while (dr.Read())
       {
           b = int.Parse(dr.GetValue(1).ToString());
           if (b > 14)
           {
               b = b - 14;
               c = 6;
           }
           else if (b > 7)
           {
               b = b - 7;
               c = 3;
           }
           else
           {
               //b = b - 7;
               c = 0;
           }
           if (dr.GetValue(2).ToString() == "L")
           {
               grdTimeTable.Rows[b].Cells[c] = dr.GetValue(0).ToString() + " (" + dr.GetValue(3).ToString() + ")";
           }
           else
           {
               grdTimeTable.Rows[b].Cells[c + 1] = dr.GetValue(0).ToString() + " (" + dr.GetValue(3).ToString() + ")";
           }
           a++;

           if ((a % 7) == 0)
           {

           }

       }



       //Alloted Faculty :
       if (conn.State == ConnectionState.Open) { conn.Close(); }
       conn.Open();
       SqlCommand cmd5 = new SqlCommand();
       SqlDataReader dr5;
       cmd5.Connection = conn;
       cmd5.CommandText = "select facultycode from fAllotmentTab where RoomNo='" + ddlSemister.SelectedValue + "' and examdate='" + d1 + "' and esession='" + ddlSession.SelectedValue + "'";
       dr5 = cmd5.ExecuteReader();
       if (dr5.Read())
       {
           lblMessage.Text = "Alloted Faculty : " + dr5.GetValue(0).ToString();
       }
       else { lblMessage.Text = "Alloted Faculty : "; }
   }




hi here m getting error like


Line 97:                 grdTimeTable.Rows[b].Cells[c] = dr.GetValue(0).ToString() + " (" + dr.GetValue(3).ToString() + ")";


Compiler Error Message: CS0200: Property or indexer 'System.Web.UI.WebControls.TableCellCollection.this[int]' cannot be assigned to -- it is read only



and one more error is

CS1061: 'System.Web.UI.WebControls.GridView' does not contain a definition for 'ColumnCount' and no extension method 'ColumnCount' accepting a first argument of type 'System.Web.UI.WebControls.GridView' could be found (are you missing a using directive or an assembly reference?)
Posted
Updated 5-Mar-12 23:38pm
v4
Comments
Manfred Rudolf Bihy 5-Mar-12 9:10am    
Title adjustment from "hi can u solve my problem?"
ythisbug 6-Mar-12 1:38am    
hi friend please help me.this s my project.i stuck in this page.any one help me?
Manfred Rudolf Bihy 6-Mar-12 5:39am    
Don't use meaningless titles like "Hi can you solve my problem". If you change this back one more time I'll just delete the whole question.
ythisbug 6-Mar-12 5:47am    
ok bro sorry

The compiler told you already what is wrong with your statement. The cell collection can not be written to, but only read from. I can only assume that you didn't want to write to the cell collection anyhow, but rather wanted to set the cell in question to a certain value. So you can try this:

C#
// Use the property Text of TableCell to set the left hand side string into the TableCell instance.
grdTimeTable.Rows[b].Cells[c].Text = dr.GetValue(0).ToString() + " (" + dr.GetValue(3).ToString() + ")";


I do suspect you'll run into other problems though as I can see that you're accessing rows that may have not yet been created yet. Since there is not enough known about your grid view and as it is passed in as a global variable (cough, cough), we don't know the current state it is in.

Regards,

Manfred
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 5-Mar-12 18:06pm    
Right, a 5.
--SA
ythisbug 5-Mar-12 22:45pm    
hi manfred thanks that i solved now m getting another error..can any one help me..

Error 1 'System.Web.UI.WebControls.GridView' does not contain a definition for 'ColumnCount' and no extension method 'ColumnCount' accepting a first argument of type 'System.Web.UI.WebControls.GridView' could be found (are you missing a using directive or an assembly reference?) C:\Users\admin\Documents\Visual Studio 2008\WebSites\SeatAllotment\RoomAllotmentDisplay.aspx.cs 44 22 C:\...\SeatAllotment\


for this m getting error..
grdTimeTable.ColumnCount = 10;
grdTimeTable.RowCount = 10;
grdTimeTable.Columns[0].Width = 100;
grdTimeTable.Columns[1].Width = 100;
grdTimeTable.Columns[2].Width = 20;
grdTimeTable.Columns[3].Width = 100;
grdTimeTable.Columns[4].Width = 100;
grdTimeTable.Columns[5].Width = 20;
grdTimeTable.Columns[6].Width = 100;
grdTimeTable.Columns[7].Width = 100;
You should really learn to use Goolgle and/or the MSDN documentation. The compiler already told you that there is no such property so you must have made a mistake. Why infact should there be a property ColumnCount on the gridview itself? The gridview already has a collection of its columns exposed as the property named, appropriately I must say, Columns. Knowing a bit about object orientation, who in your opinion should know about the number of columns present in that collection?

If your answer was the collection itself, then you are one hundred percent correct! So now you either go to the MSDN documentation and hunt down all the properties present in the collection exposed by the gridview's property named Columns, or you do some fancy guesswork as properties denoting the number of elements in some collection are usually called Count you go and try this instead:

gridViewNameWhatEverThatMayBe.Columns.Count

As I'm seeing that you are trying to assign to Count I must say you're out of luck as this property is readonly[^]. You'll have to find some other way to add columns and rows to your gridview.

Regards,

Manfred
 
Share this answer
 
Comments
ythisbug 6-Mar-12 5:56am    
yeah nice reply..thanks
ythisbug 6-Mar-12 6:07am    
hi bro i tried one code.its working but it showing in one colunm.can i set column that i have to display 7 records in one column and other in another column etc....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900