How to edit text in text box on click of button?
My datalist code is:
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Abhay ShankerRank #375 · 6.7K reputationPosted Apr 24, 2014, 10:41 PM EDT
Add another text box in Edit template
Add a button with commandName="Edit"
in datalist add OnEditCommand="DataList_EditCommand"
in .cs page
protected void DataList_EditCommand(object source,DataListCommandEventArgs e)
{
//Do your coding
}
piya p79 reputationPosted Apr 24, 2014, 11:00 PM EDT
{
Button btn = (Button)sender;
string id = btn.CommandArgument;
foreach (DataListItem item in datalist.Items)
{
TextBox tb = (TextBox)item.FindControl("txt");
if (tb.Text == id)
{
tb.ReadOnly = false;
tb.Enabled = true;
}
}
}
This is my aspx.cs code
here foreach line giving error after index 1
Error is null reference
Can you help me to change this code?