如何将gridview选定的行数据传递给另一个页面控件? [英] How to pass the gridview selected row data to another page control?

查看:125
本文介绍了如何将gridview选定的行数据传递给另一个页面控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有两个页面,一个是main.aspx,另一个是editpage.aspx.main.aspx具有gridview,在模板字段中具有一个编辑图像按钮.editpage.aspx具有一些文本框.我希望当我单击编辑图像"按钮然后进入页面时将重定向到editpage.aspx,并且该特定行的所有值都在文本框中.
请给我解决方案.我在网上搜索,但我仅获得超链接字段,而没有具有图像按钮的模板字段.
gridview是:


i have two pages one is main.aspx and other is editpage.aspx.main.aspx has gridview that has one edit image button in template field.editpage.aspx has some textboxes.i want that when i click on edit image button then page will redirect to editpage.aspx and all the values for that particular row come in the textbox.
please give me solution.i have search on net but i got only for hyperlink field not for template field that has image button.
the gridview is as:

<asp:GridView ID="grdpages" runat="server" AutoGenerateColumns="False" GridLines="Horizontal"

                        Width="715px" ShowFooter="True" DataKeyNames="pageid" 

                        OnRowEditing="grdpages_RowEditing" onrowcommand="grdpages_RowCommand">
                        <columns>
                            <asp:BoundField DataField="pagename" HeaderText="Name" />
                            <asp:TemplateField HeaderText="Home">
                                <itemtemplate>
                                    <asp:RadioButton ID="rdbtnhome" runat="server" />
                                </itemtemplate>
                                <footertemplate>
                                    <asp:Button ID="btnhomepage" runat="server" CssClass="button" PostBackUrl="~/main.aspx"

                                        Text="Home Page" />
                                </footertemplate>
                            
                            <asp:TemplateField HeaderText="Edit">
                                <itemtemplate>
                                    <asp:ImageButton ID="imgbtnedit" runat="server" ImageUrl="~/images/edit copy.png"

                                        CommandName="EditPage" CommandArgument="<%#((GridViewRow)Container).RowIndex %>" />
                                </itemtemplate>
                            
                            <asp:TemplateField HeaderText="Delete">
                                <itemtemplate>
                                    <asp:CheckBox ID="chlboxdelete" runat="server" />
                                </itemtemplate>
                                <footertemplate>
                                    <asp:Button ID="btndelete" runat="server" Text="Delete" CssClass="button" 

                                        onclick="btndelete_Click" />
                                </footertemplate>
                            
                            <asp:TemplateField>
                                <itemtemplate>
                                    <asp:HiddenField ID="hdnfieldid" runat="server" Value='<%# Eval("pageid") %>' />
                                </itemtemplate>
                            
                        </columns>

推荐答案


使用GridView RowCommand事件,

在那种情况下,您可以试试这个

if(e.CommandName =="EditPage")
Hi,
Use GridView RowCommand event,

In that event you can try this

if(e.CommandName== "EditPage")
//here you can make session eg Session["id"]=e.CommandArgument

//or can pass CommandArgument to QueryString

//and based on it retrieve data on textboxes on edit.aspx



Respone.Redirect("Edit.aspx);



Respone.Redirect("Edit.aspx);


在事件中
protected void btndelete_Click(object sender, EventArgs e)
{
   Button btn = (Button)sender;
   GridViewRow row = (GridViewRow)btn.NamingContainer;
 //do with your selected row what you want
}


在按钮上单击,将特定行的所有值保存在会话变量中
然后在第二页的页面加载中,使用这些会话变量填充不同的文本框.喜欢

On button click save all the values of particular rows in session variables
and on page load of second page fill the disered textboxes with these session variables. like

protected void imgbtnedit_Click(object sender, EventArgs e)
{
  GridViewRow Row=((Button)sender).Parent.Parent as GridViewRow;
  int index=Row.RowIndex;
  Session["Value1"]=((Label)grdpages.Rows[index].FindControl("ValueOfColumns1")).Text;
Session["Value2"]=((Label)grdpages.Rows[index].FindControl("ValueOfColumns2")).Text;
...
...
...
Response.Redirect("editpage.aspx");
}



并在页面上加载editpage.aspx



and on page load of editpage.aspx

textbox1.text=Convert.ToString(session["value1"]);
...
...


这篇关于如何将gridview选定的行数据传递给另一个页面控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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