使用c#将数据表值投标到asp.net中的gridview。 [英] Bidning the data table values row in to gridview in asp.net using c#.

查看:62
本文介绍了使用c#将数据表值投标到asp.net中的gridview。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行模式下如下



主要代码AMC(Dropdownlist1)次要代码AFF(dropdownlist2)按钮(添加)

BMC



当用户在Dropdownlist1中选择AMC并在Dropdownlist2中选择AFF并单击gridview中的添加按钮时,我希望例外输出如下



Majorcode Minorcode

AMC AFF



类似用户在dropdownlist1中选择AMC并在Dropdownlist2中选择BMC并点击添加gridview中的按钮我希望例外输出如下



Majorcode Minorcode

AMC AFF

AMC BMC


添加按钮代码如下



protected void btnadd_Click(object sender,EventArgs e)

{

Dt.Columns.AddRange(new DataColumn [2] {new DataColumn(Major Code,typeof(string)),

new DataColumn(Minor Code,typeof(string))});

Dt.Rows .Add(ddlmjrcode.SelectedItem.ToString(),ddlminorcode.SelectedItem.ToString());



gvmajormaster.DataSource = Dt;

gvmajormaster.DataBind();

}





但是当我点击gridview中的添加按钮时我得到了输出如下



Majorcode Minorcode

AMC AFF





我没有获得第二排的AMC(主要代码)和BMC(次要代码)。



i不会被排除在外如下



Majorcode Minorcode

AMC AFF

AMC BMC

我怎么能用asp做.net使用c#。



问候,

Sudha。

In Run Mode as follows

Major code AMC(Dropdownlist1) Minor code AFF(dropdownlist2) Button(Add)
BMC

When user select the AMC in Dropdownlist1 and select AFF in Dropdownlist2 and click add button in gridview i want excepted output as follows

Majorcode Minorcode
AMC AFF

Similarily when user select the AMC in dropdownlist1 and select the BMC in Dropdownlist2 and click add button in gridview i want excepted output as follows

Majorcode Minorcode
AMC AFF
AMC BMC

Add button code as follows

protected void btnadd_Click(object sender, EventArgs e)
{
Dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Major Code", typeof(string)),
new DataColumn("Minor Code", typeof(string))});
Dt.Rows.Add(ddlmjrcode.SelectedItem.ToString(), ddlminorcode.SelectedItem.ToString());

gvmajormaster.DataSource = Dt;
gvmajormaster.DataBind();
}


But when i click the add button in gridview my got output as follows

Majorcode Minorcode
AMC AFF


I am not get the AMC(Majorcode) and BMC (Minorcode) in second row.

i am not get excepted outptu as follows

Majorcode Minorcode
AMC AFF
AMC BMC
for that how can i do in asp.net using c#.

Regards,
Sudha.

推荐答案

你好,

为什么不直接将DataRow添加到DataTable。先声明一个DataRow。然后在DataTable中添加该行。尝试此代码

Hello ,
Why not you add the DataRow directly to DataTable .First declare one DataRow . and then add that row in DataTable .Try this code
//crate one datarow and set the column value accordingly .
drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow[0] = ddlmjrcode.SelectedItem.ToString();
drCurrentRow[1] = ddlminorcode.SelectedItem.ToString();

//now add the datarow in datatable
dtCurrentTable.Rows.Add(drCurrentRow);

//add set the DataSource 
gvmajormaster.DataSource = dtCurrentTable;
gvmajormaster.DataBind();



谢谢


thanks


这篇关于使用c#将数据表值投标到asp.net中的gridview。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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