怎么获取GridView当前行第一列的数据

怎么获取GridView当前行第一列的数据,第1张

protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)

{

GridViewRow row = GridView1Rows[eNewSelectedIndex];

if (rowRowState == DataControlRowStateSelected)

{

thisLabel3Text = rowCells[1]TextToString();

thistxt1Text ="你好";

}

}

但txt1中都没有值,好象都没有触发这事件,为什么?

msdn中说,当单某一行的选择BUTTON后,触发GridView1_SelectedIndexChanging事件,因此,你可以在GridView中加入选择BUTTON,然后用

protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)

{

thisResponseWrite(thisGridView1Rows[eNewSelectedIndex]Cells[4]Text);

}

GridView的数据你是怎么绑定的呢?如果是后台指定thisGridView1DataSource=Datatable;

那数据就是Datatable里的 。 如果不是你可以反过来用

DataTable dt = new DataTable();

dt = (DataTable)thisGridView1DataSource;

<asp:GridView ID="GridView1 runat="server" AutoGenerateColumns="False"

Height="69px" Width="402px"

-- 注意这里 ------------

DataKeyNames="WS_MAID" >

---------------------

<Columns>

<asp:HyperLinkField DataTextField="WS_MailObject" HeaderText="主题" />

<asp:BoundField DataField="WS_Name" HeaderText="收件人" />

<asp:BoundField DataField="WS_MailSendDate" HeaderText="日期" />

<asp:TemplateField HeaderText="全选">

<ItemTemplate>

<asp:CheckBox ID="xuanze" runat="server" />

</ItemTemplate>

<HeaderTemplate>

<asp:CheckBox ID="quanxuan" runat="server" Text="全选" />

</HeaderTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

后台代码:

for(int rowIndex = 0; rowIndex < GridView1RowsCount; rowIndex++)

{

CheckBox ch = (CheckBox)GridView1Rows[rowIndex]Cells[5]FindControl("xuanze");

if (chChecked)

{

string 邮件ID值 = GridView1DataKeys[rowIndex]ValueToString();

ResponseWrite(邮件ID值);//邮件ID即为 WS_MAID,如何得到这个WS_MAID

}

}

试一下吧,有问题留言

decimal sum1 = decimalParse(GridView1Rows[0]Cells[2]TextToString());

获取第一行第三列的数据

如果你想获得整行的数据,建议你先获取该行的主键,然后再到数据库中查询

回答问题不容易,楼主给点分吧

将你那个按钮的commandName设置为selected

dataKeyNames

设置成你的数据

主键

然后在gridview的

Rowcommand事件里面通过

eCommandArgument获得主键值

然后、、、

获取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>//codegonet/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="ViewContentaspxid={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 = daGetDataSet(sqlstr, "tb_Blog");

//创建数据表的视图

DataRowView rowview1 = mydatasetTables["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控件的数据源

GridView1DataSource = daExceDS(sqlstr);

//获取GridView控件中的主键字段

GridView1DataKeyNames = new string[] { "ST_n_id" };

//从数据库中绑定数据到列表控件中

GridView1DataBind();

}

//查看某行某列信息跳转ViewContentaspx

<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 = PageRequest["id"]ToString();

//此处用来实现将数据绑定到前台

SqlConnection mycon = new SqlConnection(ConfigurationManagerAppSettings["conStr"]);

myconOpen();

SqlDataAdapter myada = new SqlDataAdapter("select from ST_news where ST_n_id='" + str2 + "'", mycon);

DataSet ds = new DataSet();

myadaFill(ds, "ST_news");

//创建DataRowView对象的一个实例

DataRowView rowview = dsTables["ST_news"]DefaultView[0];

//将文章主题读取到labSubject文本框中

thislabSubjectText = rowview["ST_n_title"]ToString();

//将文章内容读取到txtContent文本框中

thistxtContentText = rowview["ST_n_content"]ToString();

myconClose();

}

catch (Exception ex)

{

ResponseWrite(exMessage);

}

}

}

GridView1Rows[eNewSelectedIndex]Cells[4]Text

GridView 中有SelectedIndexChanging时间可以获取你选择的行 或者用RowCommand自定义 *** 作来获取 获取到行就能获取到你要的所有数据 想放哪儿都随你!

以上就是关于怎么获取GridView当前行第一列的数据全部的内容,包括:怎么获取GridView当前行第一列的数据、怎么查询gridview中的数据、GridView 获取当前行中数据的ID等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9306338.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-27
下一篇2023-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存