怀疑在asp.net ...请清除它 [英] doubt in asp.net ...please clear it

查看:71
本文介绍了怀疑在asp.net ...请清除它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我创建了一个包含joblist的grideview。我添加了一个datadetailsview。当任何人在gridview中选择行时,它将在详细视图中显示...我在detailview中添加了一个列复选框。当有人选择复选框时单击下面的应用按钮,必须将详细视图中的数据添加到另一个应用的表中。我们可以这样做吗?





Here I created a grideview containging joblist.below that i added one datadetailsview .when anybody select the row in gridview, it will shown in detail view...I added one column checkbox in the detailview.when anbody select the checkbox and click apply button below ,the data in the detailview must be added to another table applied jobs.how can we do that?


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
 
public partial class joblist : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       if (!this.IsPostBack)
        {
            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[2] { new DataColumn("CompanyName"), new DataColumn("Designation") });
            dt.Rows.Add("NIIT", "programmer");
            dt.Rows.Add("annvision", "Webdesigner");
            dt.Rows.Add("softtech", "designer");
            dt.Rows.Add("Mahad", "Programmer");
            DetailsView1.DataSource = dt;
            DetailsView1.DataBind();
        }
  
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/secure.aspx");
    }
    protected void Page_PreRender(object sender, EventArgs e)
    {
        if (GridView1.SelectedRow == null)
        {
            DetailsView1.Visible = false;
        }
        else
        {
            DetailsView1.Visible = true;
        }
    }
    
    protected void Apply_Click(object sender, EventArgs e)
    {
        Response.Write("You are successfully applied");
        
        DataTable dt = new DataTable();
        dt.Columns.AddRange(new DataColumn[2] { new DataColumn("CompanyName"), new DataColumn("Designation") });
        foreach (DetailsViewRow row in DetailsView1.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                CheckBox chkRow = (row.Cells[0].FindControl("chkRow") as CheckBox);
                if (chkRow.Checked)
                {
                    string CompanyName = row.Cells[1].Text;
                    string Designation = (row.Cells[2].FindControl("lblDesignation") as Label).Text;
                    dt.Rows.Add(CompanyName, Designation);
                }
            }
        }
        GridView2.DataSource = dt;
        GridView2.DataBind();
 
    }
 

}



它在detailview1.DataBind()附近显示错误;

错误:用户代码未处理无效的OperationException

DataSource和DataSourceID都在DetailsView1上定义。删除一个定义。


it showing error near detailview1.DataBind();
error:Invalid OperationException was unhandled by usercode
Both DataSource and DataSourceID are defined on 'DetailsView1'. Remove one definition.

推荐答案

Quote:

错误:无效的OperationException未被处理usercode

DataSource和DataSourceID都在'DetailsView1'上定义。删除一个定义。

error:Invalid OperationException was unhandled by usercode
Both DataSource and DataSourceID are defined on 'DetailsView1'. Remove one definition.

异常非常清楚。



如果查看代码,它会变得更清晰。



在aspx页面中......

The Exception is quite clear.

If you look at your code, it becomes more clear.

In aspx page...

<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
    CellPadding="2" DataKeyNames="JobID" DataSourceID="SqlDataSource2"
    ForeColor="Black" GridLines="None" Height="50px" Width="300px"
       BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px">



在.aspx.cs页面中......


In .aspx.cs page...

protected void Page_Load(object sender, EventArgs e)
    {
       if (!this.IsPostBack)
        {
            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[2] { new DataColumn("CompanyName"), new DataColumn("Designation") });
            dt.Rows.Add("NIIT", "programmer");
            dt.Rows.Add("annvision", "Webdesigner");
            dt.Rows.Add("softtech", "designer");
            dt.Rows.Add("Mahad", "Programmer");
            DetailsView1.DataSource = dt;
            DetailsView1.DataBind();
        }

    }





您必须删除一个,因为它是冲突的,不能决定将哪个 DataSource 分配给 DetailsView


这篇关于怀疑在asp.net ...请清除它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆