如何获取gridview里某行某列的值? refer here:http://www.cnblogs.com/insus/p/3885001.html 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 GridView1.Rows[e.NewSelectedIndex].Cells[4].Text 您给的这个案例好像跟我问的对不上号啊一样的!!!also refer these:http://www.cnblogs.com/insus/archive/2011/06/30/2094151.htmlhttp://www.cnblogs.com/insus/p/3201720.htmlhttp://www.cnblogs.com/insus/p/3680461.html e.NewSelectedIndex 你这个不是获取当前选择的行号吗? 获取GridView里某行某列的值示例//GridView设置<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" CellPadding="4" Font-Size="9pt" ForeColor="#333333" GridLines="None" Width="500px" OnRowDeleting="GridView1_RowDeleting" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDataBound="GridView1_RowDataBound" PageSize="6" Height="1px"> <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> <RowStyle BackColor="#E3EAEB" /> <Columns>//codego.net/tags/11/1/ <asp:BoundField DataField="ST_n_id" HeaderText="文章ID" /> <asp:BoundField DataField="ST_n_title" HeaderText="文章主题" /> <asp:BoundField DataField="ST_n_hit" HeaderText="人气指数" /> <asp:BoundField DataField="ST_n_re" HeaderText="评论" /> <asp:HyperLinkField DataNavigateUrlFields="ST_n_id" DataNavigateUrlFormatString="ViewContent.aspx?id={0}" HeaderText="查看信息" Text="查看信息" /> <asp:CommandField HeaderText="删除" ShowDeleteButton="True" /> <asp:TemplateField HeaderText="选择"> <ItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" Font-Size="9pt" Width="9px" /> </ItemTemplate> </asp:TemplateField> </Columns> <SelectedRowStyle BackColor="#C5BBAF" ForeColor="#333333" Font-Bold="True" /> <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" /> <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#7C6F57" /> <AlternatingRowStyle BackColor="White" /> </asp:GridView>//加载数据库数据 SqlData da = new SqlData(); private static string ID; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { /*判断是否登录*/ ST_check_Login(); } //定义一个查询用户信息的SQL语句 string sqlstr = "select * from tb_Blog where UserName='" + Session["UserName"] + "'"; //调用公共类中的GetDataSet方法执行SQL语句,并返回DataSet类型的数据集 DataSet mydataset = da.GetDataSet(sqlstr, "tb_Blog"); //创建数据表的视图 DataRowView rowview1 = mydataset.Tables["tb_Blog"].DefaultView[0]; //获取注册博客的编号 ID = rowview1["BlogID"].ToString(); //调用自定义绑定方法绑定数据 ST_Article_Bind(); }//绑定数据库显示数据 public void ST_Article_Bind() { //根据获取的用户ID查询其所有文章 string sqlstr = "select * from ST_news where BlogID='" + ID + "'"; //调用公共类中的ExceDS方法,返回一个DataSet类型的数据集,并作为GridView控件的数据源 GridView1.DataSource = da.ExceDS(sqlstr); //获取GridView控件中的主键字段 GridView1.DataKeyNames = new string[] { "ST_n_id" }; //从数据库中绑定数据到列表控件中 GridView1.DataBind(); }//查看某行某列信息跳转ViewContent.aspx<asp:Label ID="labSubject" runat="server" Width="316px" Font-Size="9pt" ></asp:Label>//显示主题<asp:TextBox ID="txtContent" runat="server" Font-Size="9pt" Height="257px" TextMode="MultiLine" Width="405px"></asp:TextBox>//显示内容//加载绑定数据库内容显示数据 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { string str; string str2 = Page.Request["id"].ToString(); //此处用来实现将数据绑定到前台 SqlConnection mycon = new SqlConnection(ConfigurationManager.AppSettings["conStr"]); mycon.Open(); SqlDataAdapter myada = new SqlDataAdapter("select * from ST_news where ST_n_id='" + str2 + "'", mycon); DataSet ds = new DataSet(); myada.Fill(ds, "ST_news"); //创建DataRowView对象的一个实例 DataRowView rowview = ds.Tables["ST_news"].DefaultView[0]; //将文章主题读取到labSubject文本框中 this.labSubject.Text = rowview["ST_n_title"].ToString(); //将文章内容读取到txtContent文本框中 this.txtContent.Text = rowview["ST_n_content"].ToString(); mycon.Close(); } catch (Exception ex) { Response.Write(ex.Message); } } } 未将对象引用设置到对象的实例 循环的问题!!!!!!!!!! 关于在aspx页面中静态部分重复使用的问题 aspx文件里,要给Label的text内容调用cs里面的文件怎么处理? 诚意请教web高手,关于社区虚拟形象系统的一些问题. 一个数据库的问题 哪里有视频处理工具下载 谁给一个连接SqlServer的类! cs类中自定义函数能不能返回两个值? my97插件所在的iframe页面刷新了之后就不好使了,怎么回事? 怎样获取弹出div内文本框的值 Asp.net MVC4 寻求 导入视频 在前台可以播放的方法
http://www.cnblogs.com/insus/archive/2011/06/30/2094151.html
http://www.cnblogs.com/insus/p/3201720.html
http://www.cnblogs.com/insus/p/3680461.html
你这个不是获取当前选择的行号吗?
//GridView设置
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
CellPadding="4" Font-Size="9pt" ForeColor="#333333" GridLines="None"
Width="500px" OnRowDeleting="GridView1_RowDeleting"
OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowDataBound="GridView1_RowDataBound" PageSize="6" Height="1px">
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#E3EAEB" />
<Columns>//codego.net/tags/11/1/
<asp:BoundField DataField="ST_n_id" HeaderText="文章ID" />
<asp:BoundField DataField="ST_n_title" HeaderText="文章主题" />
<asp:BoundField DataField="ST_n_hit" HeaderText="人气指数" />
<asp:BoundField DataField="ST_n_re" HeaderText="评论" />
<asp:HyperLinkField DataNavigateUrlFields="ST_n_id" DataNavigateUrlFormatString="ViewContent.aspx?id={0}"
HeaderText="查看信息" Text="查看信息" />
<asp:CommandField HeaderText="删除" ShowDeleteButton="True" />
<asp:TemplateField HeaderText="选择">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Font-Size="9pt" Width="9px" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<SelectedRowStyle BackColor="#C5BBAF" ForeColor="#333333" Font-Bold="True" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
//加载数据库数据
SqlData da = new SqlData();
private static string ID;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
/*判断是否登录*/
ST_check_Login();
}
//定义一个查询用户信息的SQL语句
string sqlstr = "select * from tb_Blog where UserName='" + Session["UserName"] + "'";
//调用公共类中的GetDataSet方法执行SQL语句,并返回DataSet类型的数据集
DataSet mydataset = da.GetDataSet(sqlstr, "tb_Blog");
//创建数据表的视图
DataRowView rowview1 = mydataset.Tables["tb_Blog"].DefaultView[0];
//获取注册博客的编号
ID = rowview1["BlogID"].ToString();
//调用自定义绑定方法绑定数据
ST_Article_Bind();
}
//绑定数据库显示数据
public void ST_Article_Bind()
{
//根据获取的用户ID查询其所有文章
string sqlstr = "select * from ST_news where BlogID='" + ID + "'";
//调用公共类中的ExceDS方法,返回一个DataSet类型的数据集,并作为GridView控件的数据源
GridView1.DataSource = da.ExceDS(sqlstr);
//获取GridView控件中的主键字段
GridView1.DataKeyNames = new string[] { "ST_n_id" };
//从数据库中绑定数据到列表控件中
GridView1.DataBind();
}
//查看某行某列信息跳转ViewContent.aspx
<asp:Label ID="labSubject" runat="server" Width="316px" Font-Size="9pt" ></asp:Label>//显示主题
<asp:TextBox ID="txtContent" runat="server" Font-Size="9pt" Height="257px" TextMode="MultiLine"
Width="405px"></asp:TextBox>//显示内容
//加载绑定数据库内容显示数据
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
string str;
string str2 = Page.Request["id"].ToString();
//此处用来实现将数据绑定到前台
SqlConnection mycon = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
mycon.Open();
SqlDataAdapter myada = new SqlDataAdapter("select * from ST_news where ST_n_id='" + str2 + "'", mycon);
DataSet ds = new DataSet();
myada.Fill(ds, "ST_news");
//创建DataRowView对象的一个实例
DataRowView rowview = ds.Tables["ST_news"].DefaultView[0];
//将文章主题读取到labSubject文本框中
this.labSubject.Text = rowview["ST_n_title"].ToString();
//将文章内容读取到txtContent文本框中
this.txtContent.Text = rowview["ST_n_content"].ToString();
mycon.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}