带有中继器和设计部分的asp.net ...................................... [英] asp.net with repeaters and desing part.............................
本文介绍了带有中继器和设计部分的asp.net ......................................的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<%@ Page EnableEventValidation="true" Language="C#" AutoEventWireup="true" CodeFile="RpNewPage.aspx.cs" Inherits="RpNewPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body style="width: 1433px">
<form id="form1" runat="server">
<div>
<asp:Repeater ID="rptrTable" runat="server"
onitemcommand="rptrTable_ItemCommand">
<HeaderTemplate>
<table border=3>
<tr>
<th>Agent ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>City</th>
<th>SSN</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem,"AgentID") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem,"FirstName") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem,"LastName") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem,"City") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem,"SSN") %>
</td>
<td>
<asp:Button ID="btnShow" runat="server" Text="Show" CommandName="ShowButt" />
</td>
<td>
<asp:Button ID="btnEdit" runat="server" Text="Edit" CommandName="EditButt" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
而我的.cs文件是
and my .cs file is
public partial class RpNewPage : System.Web.UI.Page
{
SqlConnection connection;
SqlCommand command;
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
string strcon = ConfigurationManager.ConnectionStrings["AgentConn"].ConnectionString;
connection = new SqlConnection(strcon);
command = new SqlCommand("prcAgentShow", connection);
command.CommandType = CommandType.StoredProcedure;
connection.Open();
DataTable dt = new DataTable();
SqlDataReader dataReader = command.ExecuteReader();
dt.Load(dataReader);
rptrTable.DataSource = dt;
rptrTable.DataBind();
}
}
protected void rptrTable_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName.Equals("ShowButt"))
Label1.Text = "you clicked show butt";
}
}
从上面的iam按下浏览器中的显示按钮,它在您单击显示对接时显示
但是我想要按显示按钮时我想要相应的行AgentID
plaese help>
from the above iam pres the show button in browser it display as you clicked show butt
but i want when i press the show button i want the corresponding row AgentID
plaese help >
推荐答案
像这样更改中继器itemtemplate
Change you repeater itemtemplate like this
<ItemTemplate>
<tr>
<td>
<asp:textbox id="txt" runat="server" text=" <%# DataBinder.Eval(Container.DataItem,"AgentID") %>" xmlns:asp="#unknown"></asp:textbox>
</td>
<td>
<asp:Button ID="btnShow" runat="server" Text="Show" CommandName="ShowButt" />
</td>
<td>
<asp:Button ID="btnEdit" runat="server" Text="Edit" CommandName="EditButt" />
</td>
</tr>
</ItemTemplate>
然后在您的情况下写
and in your event write
protected void rptrTable_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName.Equals("ShowButt"))
{
TextBox txtbox=e.FindControl("txt");
Label1.Text = txtbox.Text;
}
}
或者,您可以在Repeater控件中使用Label而不是Textbox:)
Or you can use Label instead of Textbox inside Repeater control :)
使用隐藏字段",几天前我也遇到过同样的问题,我使用隐藏字段"并且我的问题已解决.
请参见下面的代码,您将有个想法...
Hi,
use Hidden Field,i too faced the same problem some days back, i used Hidden Field and my problem solved.
Plz See the below Code, you will get an idea...
<asp:GridView runat="server" ID="gv1" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
Q No.<asp:Label runat="server" ID="lblqno" Text='<%#Eval("qno") %>'></asp:Label>
<asp:Label runat="server" ID="lblque" Text='<%#Eval("que") %>'></asp:Label><br />
a. <asp:RadioButton ID="rbt1" runat="server" Text='<%#Eval("ans1") %>' GroupName="q1"/>    
b. <asp:RadioButton ID="rbt2" runat="server" Text='<%#Eval("ans2") %>' GroupName="q1"/><br />
c. <asp:RadioButton ID="rbt3" runat="server" Text='<%#Eval("ans3") %>' GroupName="q1" />    
d. <asp:RadioButton ID="rbt4" runat="server" Text='<%#Eval("ans4") %>' GroupName="q1"/><br />
<asp:HiddenField runat="server" ID="hdfqno" Value='<%#Eval("qno") %>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Mu .CS文件....
Mu .CS File....
protected void btnSubmit_Click(object sender, EventArgs e)
{
foreach (GridViewRow grow in gv1.Rows)
{
RadioButton r1 = (RadioButton)grow.FindControl("rbt1");
RadioButton r2 = (RadioButton)grow.FindControl("rbt2");
RadioButton r3 = (RadioButton)grow.FindControl("rbt3");
RadioButton r4 = (RadioButton)grow.FindControl("rbt4");
HiddenField hdf = (HiddenField)grow.FindControl("hdfqno");
if (r1.Checked == true)
{
//arr.Add(new string[] { hdf.Value, r1.Text });
arr1.Add(hdf.Value);
arr2.Add(r1.Text);
queattempted++;
}
if (r2.Checked == true)
{
arr1.Add(hdf.Value);
arr2.Add(r2.Text);
queattempted++;
//arr.Add(new string[] { hdf.Value, r2.Text });
}
if (r3.Checked == true)
{
arr1.Add(hdf.Value);
arr2.Add(r3.Text);
queattempted++;
//arr.Add(new string[] { hdf.Value, r3.Text });
}
if (r4.Checked == true)
{
arr1.Add(hdf.Value);
arr2.Add(r4.Text);
queattempted++;
//arr.Add(new string[] { hdf.Value, r4.Text });
}
if (r1.Checked == false && r2.Checked == false && r3.Checked == false && r4.Checked == false)
{
arr1.Add(hdf.Value);
arr2.Add("");
//arr.Add(new string[] { hdf.Value, "" });
}
}
SqlDataAdapter da = new SqlDataAdapter("select qno,ans from q2", cnn);
da.Fill(ds, "t2");
ArrayList dbarr = new ArrayList();
DataSet dsqno = new DataSet();
dsqno= ConvertArrayListToDataSet(arr1);
DataSet dsque = new DataSet();
dsque = ConvertArrayListToDataSet(arr2);
for(int i=0;i<ds.Tables["t2"].Rows.Count;i++)
{
string s1 = ds.Tables["t2"].Rows[i].ItemArray[0].ToString();
string s2 = dsqno.Tables[0].Rows[i].ItemArray[0].ToString();
if(s1==s2)
{
string r1=dsque.Tables[0].Rows[i].ItemArray[0].ToString();
string r2=ds.Tables["t2"].Rows[i].ItemArray[1].ToString();
if ( r1==r2 )
{
//queattempted++;
totalmarks++;
}
}
}
avg = totalmarks*100 / 30;
Session["avg1"] = avg;
Session["qattempted"] = queattempted;
Session["Remaining"] = (30 - queattempted).ToString();
Session["totalmarks"] = totalmarks;
Session["Wrong"] = (queattempted - totalmarks).ToString();
string s11; string s22;
//string s11;=minutes.ToString();
//string s22=;seconds.ToString();
s11 = (30 - minutes).ToString();
s22 = (59 - seconds).ToString(); ;
string s33 = s11+" : "+ s22;
Session["TimeTaken"] = s33;
// if(minutes==0)
Response.Redirect("ThankYou.aspx");
}
您应该使用隐藏控件和
在CS中找到隐藏的控件
或者您可以使用CommandArgument
You should use hidden control and
find hidden control in CS
or you can use CommandArgument
<asp:Button ID="Button2" runat="server" Text="Show" CommandName="ShowButt" CommandArgument='<%# Eval("AgentID") %>' />
这篇关于带有中继器和设计部分的asp.net ......................................的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文