Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<%@ 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>



and my .cs file is

C#
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";
    }
}


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 >
Posted
Updated 23-Jan-12 0:24am
v2
Comments
Member 8557191 23-Jan-12 8:13am    
<asp:textbox id="txt" runat="server" text=" <%# DataBinder.Eval(Container.DataItem,"AgentID") %>" xmlns:asp="#unknown"> THIS IS NOT WORKING WHEN IAM TRYING TO INSET THIS CODE INSIDE REPEATER REPETER IS NOT FORMED CORRECTLY THIS ERROR MSG AT DESIGN SECTION
Member 8557191 23-Jan-12 8:19am    
CODE BLOCKS ARE NOT SUPPORTED INSIDE THE CONTEXT THIS MSG IS COMMING PLEASE HELP THIS

Change you repeater itemtemplate like this

XML
<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
C#
protected void rptrTable_ItemCommand(object source, RepeaterCommandEventArgs e)
   {
       if (e.CommandName.Equals("ShowButt"))
{
TextBox txtbox=e.FindControl("txt");

           Label1.Text = txtbox.Text;
}
   }


Or you can use Label instead of Textbox inside Repeater control :)
 
Share this answer
 
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...


XML
<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"/>&nbsp&nbsp&nbsp&nbsp
                                    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" />&nbsp&nbsp&nbsp&nbsp
                                    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 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");
    }
 
Share this answer
 
v2
Comments
Member 8557191 23-Jan-12 8:21am    
WHERE IS THE HIDDEN FIELD
You should use hidden control and
find hidden control in CS
or you can use CommandArgument
XML
<asp:Button ID="Button2" runat="server" Text="Show" CommandName="ShowButt" CommandArgument='<%# Eval("AgentID") %>' />
 
Share this answer
 
Comments
Member 8557191 23-Jan-12 8:47am    
<asp:Button ID="Button2" runat="server" Text="Show" CommandName="ShowButt" CommandArgument='<%# Eval("AgentID") %>' />
this is ok to good but how to use in .cs file to return the AgentID to lable1

protected void rptrTable_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName.Equals("ShowButt"))
{
Label1.Text = "u clik the show button ";
}
Technoses 24-Jan-12 10:29am    
what do you mean : "return the AgentID to lable1 "
if you want to assign AgentId to label1 then you can use CommandArgument of e or if it not available then you can use find the button and use its property CommandArgument

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900