我试了好几次但是没有用 [英] i tried several times but it is not working
问题描述
在gridview运行模式中如下
Batchdate(gridview中只有一列)
27 2015年5月
2015年5月30日
我的代码如下
< pre lang =c#> protected void gvPkgcbndate_RowDataBound( Object sender,GridViewRowEventArgs e)
{
if (e.Row.Cells [ 1 ]。文本== dontselect)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (!( string .IsNullOrEmpty(e.Row.Cells [ 1 ]。文字)))
{
LinkButton lnk = new LinkButton();
lnk.ID = lnk;
lnk.Text = 点击此处;
e.Row.Cells [ 1 ]。Controls.Add(lnk);
}
}
}
受保护 void lnk_Click( object sender,EventArgs e)
{
try
{
var exists = lbllist.Items.FindByValue(gvPkgcbndate.SelectedRow.Cells [ 1 跨度>]文本)。
string [] smsg = gvPkgcbndate.SelectedRow.Cells [ 1 ]。Text.Split( ' - ');
string txt1 = smsg [ 1 ]。ToString()。Trim();
lbllist.Items.Add(txt1.Substring( 0 ,txt1.Length - 2 ) );
}
catch (例外情况)
{
lblErr.Text = ex.Message.ToString();
}
}
受保护 void gvPkgcbndate_DataBound( object sender,EventArgs e)
{
lnk_Click(sender,e);
}
但是当我在lnk _click中运行时显示错误如下/>
错误如下
对象参考未设置为对象实例。
在lnk点击我提到下面的一个是正确的
gvPkgcbndate.SelectedRow.Cells [1] .Text 使用调试器。
在 gvPkgcbndate_RowDataBound
和 lnk_Click
方法的顶部放置一个断点,然后看看确切地说你正在处理什么。
使用调试器检查各种变量和变量部分(将鼠标悬停在它们上面,或使用Watch窗格)和找出哪一个是 null
。
我们不能为你做到这一点 - 我们无法运行你的代码,我们也没有拥有你的数据!
当你知道哪一个是空的时候,你可以开始寻找原因 - 但直到你知道,没有任何人可以做。
In gridview run mode as follows
Batchdate (only one column in gridview)
27 May 2015
30 May 2015
My code as follows
protected void gvPkgcbndate_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.Cells[1].Text == "dontselect")
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (!(string.IsNullOrEmpty(e.Row.Cells[1].Text)))
{
LinkButton lnk = new LinkButton();
lnk.ID = "lnk ";
lnk.Text = "click here";
e.Row.Cells[1].Controls.Add(lnk);
}
}
}
protected void lnk_Click(object sender, EventArgs e)
{
try
{
var exist = lbllist.Items.FindByValue(gvPkgcbndate.SelectedRow.Cells[1].Text);
string[] smsg = gvPkgcbndate.SelectedRow.Cells[1].Text.Split('-');
string txt1 = smsg[1].ToString().Trim();
lbllist.Items.Add(txt1.Substring(0, txt1.Length - 2));
}
catch (Exception ex)
{
lblErr.Text = ex.Message.ToString();
}
}
protected void gvPkgcbndate_DataBound(object sender, EventArgs e)
{
lnk_Click(sender, e);
}
But when i run shows error as follows in the lnk _click
error as follows
object referebce not set to an instance of object.
in lnk click i mention the below one is correct
gvPkgcbndate.SelectedRow.Cells[1].Text
Use the debugger.
Put a breakpoint at the top of both thegvPkgcbndate_RowDataBound
andlnk_Click
methods, and look at exactly what you are dealing with.
Use the debugger to examine the various variables and parts of variables (hover the mouse over them, or use the Watch pane) and find out which one isnull
.
We can't do that for you - we can't run your code, and we don't have your data!
When you know which one is null, you can start to look for why - but until you do know, there is nothing anyone can do.
这篇关于我试了好几次但是没有用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!