c# 有内容但赋值为空
usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingS...
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class ucNotice : System.Web.UI.UserControl
{
string myConnetionString = "server=;uid=sa;pwd=123456;database=b2b;";
SqlConnection myConnection = new SqlConnection();
string cmdString = "select * from notice";
SqlCommand myCommand;
SqlDataReader myReader;
string content;
LinkButton l;
protected void Page_Load(object sender, EventArgs e)
{
GridViewBind();
}
private void GridViewBind()
{
myConnection.ConnectionString = myConnetionString;
myConnection.Open();
myCommand = new SqlCommand(cmdString, myConnection);
myReader = myCommand.ExecuteReader();
DataList1.DataSource = myReader;
DataList1.DataBind();
this.DataList1.DataKeyField="content";
}
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
}
public string Content()
{
return content;
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
l.PostBackUrl = "~/ShowNotice.aspx";
myReader.Close();
myConnection.Close();
}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
l = (LinkButton)e.Item.FindControl("LinkButton1");
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if(e.CommandName=="link1")
{
DataList1.SelectedIndex = e.Item.ItemIndex;
string content1 = DataList1.SelectedValue.ToString();
//就是上一句content1为空 ,奇怪的就是 DataList1.SelectedValue的值是一串中文哦 编译器上显示的我真的晕死,找了很多办法没撤。
string num = (string)DataList1.DataKeys[e.Item.ItemIndex];
}
}
}
在上面的方法体内无论什么字符串都不行自己打的都不行,一律为空,我的天,是不是电脑烧坏了脑子 展开
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class ucNotice : System.Web.UI.UserControl
{
string myConnetionString = "server=;uid=sa;pwd=123456;database=b2b;";
SqlConnection myConnection = new SqlConnection();
string cmdString = "select * from notice";
SqlCommand myCommand;
SqlDataReader myReader;
string content;
LinkButton l;
protected void Page_Load(object sender, EventArgs e)
{
GridViewBind();
}
private void GridViewBind()
{
myConnection.ConnectionString = myConnetionString;
myConnection.Open();
myCommand = new SqlCommand(cmdString, myConnection);
myReader = myCommand.ExecuteReader();
DataList1.DataSource = myReader;
DataList1.DataBind();
this.DataList1.DataKeyField="content";
}
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
}
public string Content()
{
return content;
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
l.PostBackUrl = "~/ShowNotice.aspx";
myReader.Close();
myConnection.Close();
}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
l = (LinkButton)e.Item.FindControl("LinkButton1");
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if(e.CommandName=="link1")
{
DataList1.SelectedIndex = e.Item.ItemIndex;
string content1 = DataList1.SelectedValue.ToString();
//就是上一句content1为空 ,奇怪的就是 DataList1.SelectedValue的值是一串中文哦 编译器上显示的我真的晕死,找了很多办法没撤。
string num = (string)DataList1.DataKeys[e.Item.ItemIndex];
}
}
}
在上面的方法体内无论什么字符串都不行自己打的都不行,一律为空,我的天,是不是电脑烧坏了脑子 展开
若以下回答无法解决问题,邀请你更新回答
2个回答
展开全部
DataList1.SelectedValue这个东西是object类型的,不要直接用ToString()方法
你先在这里把DataList1.SelectedValue的类型转一下.
你先在这里把DataList1.SelectedValue的类型转一下.
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的gridview 绑定 SqlDataReader myReader??????????能绑定出来你查询出来的所有数据吗》?????
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询