ASP.NET - ASP.NET  ASP.NET - ASP.NET

Asked By karthik
19-Apr-10 03:31 AM
When I click a row on datagridview1 I want the corresponding row to get inserted in datagridview2 how do I do it? Please help me!
If possible help me with the source code!
Thanks in advance!

  Anoop S replied to karthik
19-Apr-10 03:52 AM
write code in GridView1_SelectedIndexChanged event in GridView1

GridView2.Rows.add(GridView1.Rows(GridView1.SelectedIndex))
  karthik replied to Anoop S
19-Apr-10 04:04 AM
I get the following errors.



Error 1 'System.Web.UI.WebControls.GridViewRowCollection' does not contain a definition for 'add' D:\Sample Projects\19th-Apr\Gridview_CheckBox_Delete\GridView_CheckBox_Delete.aspx.cs 90 24 D:\...\Gridview_CheckBox_Delete\
Error 2 'System.Web.UI.WebControls.GridView.Rows' is a 'property' but is used like a 'method' D:\Sample Projects\19th-Apr\Gridview_CheckBox_Delete\GridView_CheckBox_Delete.aspx.cs 90 38 D:\...\Gridview_CheckBox_Delete\

  Anoop S replied to karthik
19-Apr-10 04:10 AM
Its square brackets 
GridView2.Rows.add(GridView1.Rows[GridView1.SelectedIndex])
  Anoop S replied to Anoop S
19-Apr-10 04:12 AM
GridView2.Rows.Add(GridView1.Rows[GridView1.SelectedIndex])
  karthik replied to Anoop S
19-Apr-10 05:17 AM
Hi Anoop!!!
    I'm working with C#, and I dont get the 'add' option. 
When I try using the code I get the following error.

Error 1 'System.Web.UI.WebControls.GridViewRowCollection' does not contain a definition for 'add'

How do I resolve it.
Its urgent.
Help me if yo can.

  Anoop S replied to karthik
19-Apr-10 05:22 AM
its Add not add
  karthik replied to Anoop S
19-Apr-10 09:08 AM
I tried 'Add' instead of 'add' but you know what...
   It still shows up the same error.

HELP ME!
  shraddha bhosale replied to karthik
19-Apr-10 09:24 AM

Hi Karthik,
    I have done the same code in C#.Net windows application. Please try following code;
    Please take two DataGridView controls on your form first, before you start coding.

 

 

private void Form1_Load(object sender, EventArgs e)

 

{

 

try

 

{

 

DataTable dt = new DataTable();

 

dt.Columns.Add(

"Column1");

 

dt.Columns.Add(

"Column2");

 

 

DataRow dr;

 

 

//to add runtime data in first DataGridView control

 

for (int i = 0; i < 3; i++)

 

{

dr = dt.NewRow();

dr.BeginEdit();

dr[

"Column1"] = "Name" + (i + 1);

 

dr[

"Column2"] = "Address" + (i + 1);

 

dr.EndEdit();

dt.Rows.Add(dr);

}

dataGridView1.DataSource = dt;

}

 

catch (Exception ex)

 

{

 

MessageBox.Show(ex.Message);

 

}

}


 

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)

 

{

 

try

 

{

 

if (dataGridView2.Columns.Count == 0)

 

{

dataGridView2.Columns.Add(

"Col1", "Column1");

 

dataGridView2.Columns.Add(

"Col2", "Column2");

 

}

dataGridView2.Rows.Add();

 

int index = dataGridView1.CurrentRow.Index; //index of selected row from Datagrid1

 

 

int index1 = dataGridView2.Rows.Count; //row index of second DataGrid, where you want to copy the row

 

 

if (index1 == 0)

 

index1 = 0;

 

else

 

index1 = index1 - 2;

 

for (int j = 0; j < dataGridView1.Rows[0].Cells.Count; j++)

 

dataGridView2.Rows[index1].Cells[j].Value = dataGridView1.Rows[index].Cells[j].Value;

}

 

catch (Exception ex)

 

{

 

MessageBox.Show(ex.Message);

 

}

}


Hope, this will help you

thanks

  Super Man replied to karthik
19-Apr-10 10:38 AM

Hi there is no method for adding column in asp.net

 

You can get datatable from griview datasource and

Add in datatable  and again bind with this datatable to gridview2.

 

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

    {

        DataTable dt = ((DataTable)GridView2.DataSource);

        dt.Rows.Add(GridView1.SelectedRow);

        GridView2.DataSource=dt;

        GridView2.DataBind();

    }

 

 

  karthik replied to shraddha bhosale
20-Apr-10 03:17 AM
Hi shradha,

             It's working fine with windows application but I need one for web application. 
Help me if yo... can!
  karthik replied to Super Man
20-Apr-10 03:21 AM
Hi khan,

     I tried using it but it does'nt seem to be working!!!
The second gridview does'nt show up when I execute it.
   This s... very urgent n im really very down... can you help me?
  shraddha bhosale replied to karthik
20-Apr-10 03:39 AM

Hi Karthik

               Please try below code for asp.net;

 

protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add(
"Column1");
dt.Columns.Add(
"Column2");
dt.AcceptChanges();

 

 

ViewState[

"key1"] = dt;
DataTable dt1 = new DataTable();
dt1.Columns.Add(
"Column1");
dt1.Columns.Add(
"Column2");

 

 

DataRow dr;
for (int i = 0; i < 3; i++)
{
dr = dt1.NewRow();
dr.BeginEdit();
dr[
"Column1"] = "Name" + (i + 1);
dr[
"Column2"] = "Address" + (i + 1);
dr.EndEdit();
dt1.Rows.Add(dr);
}

 

GridView1.DataSource = dt1;
GridView1.DataBind();
}
}

catch (Exception ex)
{
Response.Write(ex.Message);
}
}

 

 

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
DataTable dt = (DataTable)ViewState["key1"];
DataRow dataRow;
dataRow = dt.NewRow();

 

 

int i2 = 1;
for (int i = 0; i < dataRow.Table.Columns.Count; i++)
{
dataRow[i] = GridView1.SelectedRow.Cells[i2].Text;
i2++;
}

 

dt.Rows.Add(dataRow);
dt.AcceptChanges();
GridView2.DataSource = dt;
GridView2.DataBind();
}

 

catch (Exception ex)
{
Response.Write(ex.Message);
}

 

}

  karthik replied to shraddha bhosale
20-Apr-10 03:54 AM
Hey shraddha,
                     The first Grid displays the data but I couldn Click or work with it. Its jus showin the data. And  unfortunately the second is not showing up what do I... do?
No errors during compilation.
  shraddha bhosale replied to karthik
20-Apr-10 05:00 AM
Hi Kartik,

              Sorry i forgot to tell you one thing related to Gridview1;
 
              Please set it's AutoGenerateSelectButton property to true, so you can select rows from GridView1

Thanks
  karthik replied to shraddha bhosale
21-Apr-10 12:35 AM
Hi Shradhha,
  
              Your Amazing you have done a wonderful job... Hatz... off!!!
      My problemz... solved. Shradhha you rock!
  karthik replied to karthik
21-Apr-10 09:00 AM
 Dere's another doubt,
           You have coded using two data tables.
       But I want it using data set. When I try using dataset the  ' dt.Rows.Add(dataRow);' option and 'dataRow = dt.NewRow();' option does'nt work. 
    What do I do?
Create New Account
help
me the FAQs on Masterpages in asp.net. Thanks alot var Hi What are Master Pages in ASP.NET? or What is a Master Page? ASP.NET master pages allow you to create a consistent layout for the pages in your application. A single master page defines the look and feel and standard behavior that you want for all of the pages (or a group of pages) in your application. You can then create individual content pages that contain the content you want to display. When users request the content pages, they
using cache object of ASP.NET? (B) How can you cache different version of same page using ASP.NET cache object? (A) How will implement Page Fragment Caching? (B) Can you compare ASP.NET sessions with classic ASP? (B) Which are of using Query Strings? (I) What is Absolute and Sliding expiration? (I) What is cross page posting? 93 (I) How do we access viewstate value of this page in the next page ? (I) Can we post and access view state in another application? (I) What is SQL In which event are the controls fully loaded? (B) How can we identify that the Page is Post Back? (B) How does ASP.NET maintain state in between subsequent request? (A) What is event bubbling? B) How do we assign page specific attributes? (A) How do we ensure viewstate is not tampered? (B) What is the control are valid and proper? (A) If client side validation is enabled in your Web page, does that mean server side code is not run. (A)Which JavaScript file is referenced
renders the same css differently. Very odd. Sir also some other features : in our profile page we are not able to see the symbol of answer unchecked, checked , ignored, 3* , 1 just missed that feature. Sir, now most of things are working fine as expected ! Profile page , My Post Page etc working good ! site looks great ! Sir one thing i notice . . Every posts has the asp-net / 17 / 10371909 / gridview-sorting-using-jquery.aspx Navigation menu missing in forum merit page http: / / www.eggheadcafe.com / forummerit.aspx Regards Hi Robbe, I suggest you that, if you hi. . previously there is dropdownlist in which we used to select number of posts per page . . . but in the New site it is missing. . . . hi. . . check out the belowlines 2 Replies each Answer posted Hi Robbe, After giving replay for the question and submitting the button, page is showing the top of the page. My suggestion is if the page shows the answer which we have replied wiil be better. hi. . in the below link
while creating an ASP.NET application? There are two level of asp.net debugging 1. Page level debugging For this we have to edit the page level debugging enable the trace to true in the line in the html format of the page. %@ Page Language = ”vb” trace = ”true”AutoEventWireup = ”false” Codebehind = ”WebForm1.aspx.vb” Inherits = ”WebApplication2.WebForm1?&gt; 2 Enable trace enabled = true. If there is a calendar control to be included in each page of your application, and and we do not intend to use the Microsoft-provided calendar do you develop it? Do you copy and paste the code into each and every page of your application? Create the Calendar User Control The control we will create will contain Specify the best ways to store variables so that we can access them in various pages of ASP.NET application? Declare the variables in Global.aspx How many objects are there cookies: Session cookies Persistent cookies Tell few steps for optimizing (for speed and resource) ASP page / application. Avoid mixing html code with asp code Which command using Query Analyzer will give
Page Directive? What is the purpose of page directive in aspx page? Directive Syntax Directives are instructions used to specify settings (related to how a page should render and processed) used by the page and user control compilers when they process ASP.NET Web Forms page (.aspx) and user control (.ascx) files. These are the essential part of every ASP.NET Page or Control. Directives can be located anywhere in an .aspx or .ascx file, but the values, same as any HTML tag) that are specific to that directive. Special Note: The @ Page directive can be used only in .aspx files, and the @ Control directive can be used