按钮列选择。 [英] Button Column Select.

查看:76
本文介绍了按钮列选择。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个带有Button列的数据网格,以超链接的形式选择。在

同一页面上,我有另一个插入数据的数据网格和一个

列(Name)具有插入数据的用户的名称(使用windows

身份验证)。

现在这就是它应该如何工作:当任何用户想要查看关于特定用户的数据时,它是一个特定用户选择他的名字的问题和所选用户写的数据应该是唯一要显示的数据。

我在Google上有一些例子,但他们似乎都没有工作。

当用户被选中时,页面保持相同的数据不是选择的b $ b。我怎么能解决这个问题呢?

我的代码如下:

HTML部分:

< Columns>

< asp:ButtonColumn HeaderText =" Operations"

DataTextField =" TeamOperation" ButtonType =" LinkBut​​ton">< /

asp:ButtonColumn>

< / Columns>

和代码背后:

private void dgoperation_ItemCommand(对象源,

System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

SqlCommand myCommand = new SqlCommand();

myCommand.Connection = con;

myCommand.CommandText =" select * from dbo.DashBoard其中Name =

@ Billing" ;;

myCommand.Parameters.Add(new SqlParameter(" @Billing",SqlDbType.VarChar,

50));

myCommand.Parameters [" @ Billing"]。Value = dgbilling;

SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);

DataSet ds = new DataSet() ;

myAdapter.Fill(ds);

dgis.DataSource = ds;

dgis.EditItemIndex = -1;

dgis.DataBind();

}


dgis:这是用户插入数据的数据网格。

dbbilling:这是带有名单的数据网格。

谢谢。

Hi all,
I have a datagrid with Button column select in form of hyperlink. On
the same page, I have another datagrid that insert data and one
column(Name) has Names of a user that is inserting data(using windows
authentication).
Now this is how it''s supposed to work: When any user want to see data
about a particular user it''s a matter of selecting his name and the
data Writen by the selected user should be the only ones to be shown.
I got some examples on Google but they all seem not to be working.
When a user is selected the page remains the same data is not
selected. How would can I solve this problem?
My code looks like this:
HTML part:
<Columns>
<asp:ButtonColumn HeaderText="Operations"
DataTextField="TeamOperation" ButtonType="LinkButton"></
asp:ButtonColumn>
</Columns>
and code behind:
private void dgoperation_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
SqlCommand myCommand=new SqlCommand();
myCommand.Connection=con;
myCommand.CommandText="select * from dbo.DashBoard where Name =
@Billing";
myCommand.Parameters.Add(new SqlParameter("@Billing",SqlDbType.VarChar,
50));
myCommand.Parameters["@Billing"].Value= dgbilling;
SqlDataAdapter myAdapter=new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
myAdapter.Fill(ds);
dgis.DataSource=ds;
dgis.EditItemIndex = -1;
dgis.DataBind();
}

dgis: this is the datagrid that where user inserts data.
dgbilling: this is the datagrid with the name list.
Thanks.

推荐答案

我已经更正了我的陈述,这次我收到此错误:

对象引用未设置为对象的实例。

错误来源:

第219行:myCommand.CommandText =" select * from dbo.DashBoard

Name Like @ Billing" ;;

第220行:myCommand.Parameters.Add(new

SqlParameter(" @Billing",SqlDbType.VarChar,50));

第221行:myCommand.Parameters [" @ Billing"]。值= bc。文字;

第222行:SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);

第223行:DataSet ds = new DataSet();

是我的代码:

< Columns>

< asp:ButtonColumn HeaderText =" Operations"

DataTextField =" TeamOperation" ButtonType =" LinkBut​​ton"

CommandName =" Select">< / asp:ButtonColumn>

< / Columns>

我的代码背后:

private void dgoperation_ItemCommand(对象来源,

System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

System.Web.UI.WebControls.LinkBut​​ton bc = new

System.Web.UI.WebControls.LinkBut​​ton();

bc =(系统。 Web.UI.WebControls.LinkBut​​ton)e.Item.Ce lls [0] .FindControl(" TeamBilling");

SqlCommand myCommand = new SqlCommand();

myCommand.Connection = con;

myCommand.CommandText =" select * from dbo.DashBoard其中Name Like

@ Billing" ;;

myCommand .Parameters.Add(new SqlParameter(" @Billing",SqlDbType.VarChar,

50));

myCommand.Parameters [" @ Billing"]。 = bc.Text;

SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);

DataSet ds = new DataSet();

myAdapter.Fill(ds);

dgis.DataSource = ds;

dgis.EditItemIndex = -1;

dgis.DataBind();

}

如何解决这个问题?

谢谢

I have corrected my statement and this time I''m getting this error:
"Object reference not set to an instance of an object."
And the error source:
Line 219: myCommand.CommandText="select * from dbo.DashBoard where
Name Like @Billing";
Line 220: myCommand.Parameters.Add(new
SqlParameter("@Billing",SqlDbType.VarChar,50));
Line 221: myCommand.Parameters["@Billing"].Value= bc.Text;
Line 222: SqlDataAdapter myAdapter=new SqlDataAdapter(myCommand);
Line 223: DataSet ds = new DataSet();
This is my code:
<Columns>
<asp:ButtonColumn HeaderText="Operations"
DataTextField="TeamOperation" ButtonType="LinkButton"
CommandName="Select"></asp:ButtonColumn>
</Columns>
My code behind:
private void dgoperation_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
System.Web.UI.WebControls.LinkButton bc=new
System.Web.UI.WebControls.LinkButton();
bc=(System.Web.UI.WebControls.LinkButton)e.Item.Ce lls[0].FindControl("TeamBilling");
SqlCommand myCommand=new SqlCommand();
myCommand.Connection=con;
myCommand.CommandText="select * from dbo.DashBoard where Name Like
@Billing";
myCommand.Parameters.Add(new SqlParameter("@Billing",SqlDbType.VarChar,
50));
myCommand.Parameters["@Billing"].Value= bc.Text;
SqlDataAdapter myAdapter=new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
myAdapter.Fill(ds);
dgis.DataSource=ds;
dgis.EditItemIndex = -1;
dgis.DataBind();
}
How can I solve this?
Thanks


5月18日下午3:14,rcoco< nclau ... @ yahoo.cawrote:
On May 18, 3:14 pm, rcoco <nclau...@yahoo.cawrote:

myCommand.Connection = con;
myCommand.Connection=con;



什么是骗子?你是否已经创建了一个SqlConnection引用?


例如,
SqlConnection con = new SqlConnection(" my_connection_string");

What is ''con''? Did you created a SqlConnection reference already?

For example,

SqlConnection con = new SqlConnection("my_connection_string");


您好Alexey,

con是:

SqlConnection con = new SqlConnection(" user

id = utldbuser;" +" password = utldbuser;" +" server = utlhq 202;" +" database = IS_dashboard;");

谢谢

Hi Alexey,
con is:
SqlConnection con = new SqlConnection("user
id=utldbuser;"+"password=utldbuser;"+"server=utlhq 202;"+"database=IS_dashboard;");
Thanks


这篇关于按钮列选择。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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