I have one form having One DataList In which i have two table one having Header Template and other having Item Template.......

Code Of aspx page is as follows.....

    <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">

            <HeaderTemplate>
        <div>
            <table>
                <tr>

                    <td style="width:245px; text-align:center;">
                        Image</td>
                    <td style="width:450px;text-align:center;">
                        Item Description</td>
                    <td style="width:260px;text-align:center;">
                        Price</td>
                    <td style="width:322px;text-align:center;">
                        Qty</td>
                    <td style="width:300px;text-align:center;">
                        Remove</td>
                    <td style="width:310px;text-align:center;">
                        Total</td>
                </tr>
            </table>
            </div>
        </HeaderTemplate>
        <ItemTemplate>
            <div>
            <table class="style1" style="border:solid 3px purple">
                <tr>
                    <td style="width:200px;border: thin ridge #FF00FF;">
                        <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("Product_Image") %>' Height="100px" Width="100px" />

                        &nbsp;</td>
                    <td style="width:500px;border: thin ridge #FF00FF;">
                    <asp:Label ID="Item_DescriptionLabel" runat="server" 
                Text='<%# Eval("Item_Description") %>' />

                        &nbsp;</td>
                    <td style="width:300px;border: thin ridge #FF00FF;text-align:center;    ">
                    <asp:Label ID="PriceLabel"  runat="server" Text='<%# Eval("Price") %>' />

                        &nbsp;</td>
                    <td style="width:300px;border: thin ridge #FF00FF;">

                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                    <asp:Label ID="QtyLabel" runat="server" Text='<%# Eval("Qty") %>' />
                        <br>
                        <br></br>
                        <asp:LinkButton ID="LinkButton1" runat="server">Change</asp:LinkButton>
                        &nbsp;</br>
                        </td>
                    <td style="width:300px;border: thin ridge #FF00FF;">
                        <asp:ImageButton ID="ImageButton1" runat="server" />
                        &nbsp;</td>
                    <td style="width:300px;border: thin ridge #FF00FF;">
                        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                        &nbsp;</td>
                </tr>
            </table>
            </div>
          </ItemTemplate>
    </asp:DataList>

As you can see there is a td tag having one label,textbox and linkbutton

<td style="width:300px;border: thin ridge #FF00FF;">

                            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                        <asp:Label ID="QtyLabel" runat="server" Text='<%# Eval("Qty") %>' />
                            <br>
                            <br></br>
                            <asp:LinkButton ID="LinkButton1" runat="server">Change</asp:LinkButton>
                            &nbsp;</br>
                            </td>

Now on this LinkButton click i want to make visibility of textbox to true bydefault it will be false and also the linkbutton text to Save............

cs file code............

        if (Session["Customer_ID"] == null)
        {
            Response.Redirect("LogIn.aspx");
        }
        else
        {
            string id = Session["Customer_ID"].ToString();
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "Data Source=HP-HP\\SQLEXPRESS;Initial Catalog=OnlineShop;Persist Security Info=True;User ID=sa;Password=rane@1234";
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from Cart where Customer_ID='"+id+"'", con);
            SqlDataReader dr = cmd.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Load(dr);
            DataList1.DataSourceID = null;
            DataList1.DataSource = dt;
            DataList1.DataBind();
            con.Close();
        }

So in the click procedure... outside of the if..then conditional block...

TextBox1.visible = false;
LinkButton1.text = "Save";

On Click event of linkbutton i cannot find textbox1 and linkbutton1 because its in datalist.......... Its not that simple........

sorry, missed that part..you should be able to use the FindControl() method. I'am doing this from memory in VB, but it would be something like this...

Dim myText
For x = 0 To myDataList.Items.Count - 1  
  myText = DataList1.Items(x).FindControl("TextBox1")  
  TextBox1.Text = TextBox1.Text & "<br />" & myText.Text  
Next

Its not working and i want to disable label and enable textbox dont want to assign any text to textbox.......

That was just an example. If you use the FindControl method and assign it to a variable, in the example I provided it would be myText, then you can manipulate that object.

To "enable" or make it visible, you would just do this on line #4:
myText.visible = true

Use the same approach for the label. If this is not helpful, I can provide additional detail once i have my IDE in front of me. at the moment, these suggestions are from memory.

Thanks a lot JorgeM....
Really appreciate your help.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.