同上,如何在DataGrid中跳转页面,并希望在跳转页面的时候能够得到DataGrid中第一列的值,希望好心人提供一下代码50分献上!
解决方案 »
- 怎样用JavaScript代码将table表格与SqlServer2005数据库中的表进行绑定呢
- asp.net框架页面,左侧为导航,右侧为内容,点击左侧,右侧内容替换,F5后,左右侧如何能够保持原来页面呢?谢谢,在线等10分钟
- 数据库
- 字符串替换 问题
- 有没有用于asp.net开发的企业库的资料啊?
- 请教:windows2000 server系统上如何访问 windows 2003 server系统上的数据库Sql Server 2000?
- 关于Datagrid中数据编辑,更新的问题
- 为什么在gif图片上做了叠加水印后生成的gif/jpg图片色彩清晰度不同?(有图为证)
- 请高手帮帮忙啊
- 求助,在datagrid中,我怎样定制模块才能将原数据中的0,1改为审核和未审核?
- gridview中嵌套checkbox,怎样限制checkbox多选,急!!!在线等!!!
- 求教高手帮我解决这个问题啊,现在真的很急!!
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server">HyperLink</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
后台代码:protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
foreach (GridViewRow grRow in this.GridView1.Rows)
{
HyperLink dr = (HyperLink)grRow.Cells[26].FindControl("HyperLink1");
if (dr != null)
{
dr.NavigateUrl = "~/Default.aspx?id="+grRow.Cells[0].Text;
}
}
}
在里面编辑url和要传的参数
希望说的详细一点吧,我希望在DataGrid上添加一个按钮叫更新,当我点击这个按钮的时候可以跳转到另一个页面,并且得到被选择DataGrid中行的ID,谢谢了!分不够的话还可以再加!
{
foreach (GridViewRow grRow in this.GridView1.Rows)
{
HyperLink dr = (HyperLink)grRow.Cells[26].FindControl("HyperLink1");
if (dr != null)
{
dr.NavigateUrl = "~/Default.aspx?id="+grRow.Cells[0].Text;
}
}
}这个方法不知道是什么意思,有人可以告诉一下吗
前台:这里注意,用到了CommandName属性。
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CommandName="Upda" Text="更新" />
</ItemTemplate>
</asp:TemplateField>
后台代码:这样就 可以了。你试试
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
foreach (GridViewRow grRow in this.GridView1.Rows)
{
Button bt = (Button)grRow.Cells[27].FindControl("Button1");
if(bt!=null)
{
bt.CommandArgument=grRow.Cells[0].Text;
}
HyperLink dr = (HyperLink)grRow.Cells[26].FindControl("HyperLink1");
if (dr != null)
{
dr.NavigateUrl = "~/Default.aspx?id="+grRow.Cells[0].Text;
}
}
}protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Upda")
{
string url = "~/Default.aspx?id="+e.CommandArgument.ToString();
Response.Redirect(url);
}
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)//创建GridView的Row事件
foreach (GridViewRow grRow in this.GridView1.Rows) //遍历GridView的Row
HyperLink dr = (HyperLink)grRow.Cells[26].FindControl("HyperLink1"); //获取模板列里HyperLink控件
if (dr != null) //是否获取到HyperLink控件
dr.NavigateUrl = "~/Default.aspx?id="+grRow.Cells[0].Text; //定义HyperLink的转向Url
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CommandName="Upda" Text="更新" />
</ItemTemplate>
的
这样吧,我把自己的代码拿出来,大家看一下吧
前台
<asp:DataGrid id="DataGrid1" runat="server" Width="819px" Height="318px" AutoGenerateColumns="False"
PageSize="3" AllowPaging="True" DataKeyField="id">
<Columns>
<asp:BoundColumn></asp:BoundColumn>
<asp:BoundColumn DataField="id" HeaderText="项目ID号"></asp:BoundColumn>
<asp:BoundColumn DataField="business_man" HeaderText="销售员"></asp:BoundColumn>
<asp:BoundColumn DataField="tac_time" HeaderText="交单时间"></asp:BoundColumn>
<asp:BoundColumn DataField="contract_time" HeaderText="合同签订时间"></asp:BoundColumn>
<asp:BoundColumn DataField="achieve_time" HeaderText="完成时间"></asp:BoundColumn>
<asp:BoundColumn DataField="sun_price" HeaderText="总价格"></asp:BoundColumn>
<asp:BoundColumn DataField="paid" HeaderText="已付款"></asp:BoundColumn>
<asp:BoundColumn DataField="balance" HeaderText="余款"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
那是GridView的啊
DataGrid用的话,你改一下再用它啊。郁闷了
这次是DataGrid的
前台代码:
<asp:TemplateColumn FooterText="更新" HeaderText="更新">
<ItemTemplate>
<asp:Button ID="Button2" runat="server" CommandName="BtUp" Text="更新" />
</ItemTemplate>
</asp:TemplateColumn>
后台代码:
protected void DataGrid1_ItemCreated(object sender, DataGridItemEventArgs e)
{
foreach (DataGridItem gr in this.DataGrid1.Items)
{
Button bt = (Button)gr.Cells[2].FindControl("Button1");
if (bt != null)
{
bt.CommandArgument = gr.Cells[0].Text.ToString();
}
}
}
protected void DataGrid1_ItemCommand(object source, DataGridCommandEventArgs e)
{
if (e.CommandName == "BtUp")
{
string url = "~/Default.aspx?id=" + e.CommandArgument.ToString();
Response.Redirect(url);
}
}
{
if (e.CommandName == "BtUp")
{
string url = "~/Default.aspx?id=" + this.DataGrid1.Items[e.Item.ItemIndex].Cells[0].Text;
Response.Redirect(url);
}
}更正一下
用这个就可以可以把那个ItemCreated事件去掉,这个没用到
只可惜分太少了,我还有个问题,又另外开了个帖子,也是关于DataGrid1的,希望你来看一下吧!谢谢!
this.DataGrid1.Items[e.Item.ItemIndex].Cells[0].Text;是传不出去的
只有
DataGrid1.DataKeys[(int)e.Item.ItemIndex].ToString();
可以传出去了
怎么传不过去?
我这里试了是可以传的;
DataGrid1.DataKeys[(int)e.Item.ItemIndex]这样只可以取DataKeys的值,也就是你设置给DataGrid的DataKey的字段值
而this.DataGrid1.Items[e.Item.ItemIndex].Cells[0].Text可以取DataGrid所有列的值,模板列转换一下就可以。你说不可以,估计是你哪里写错了。。