c# listbox选中项在textbox显示并可修改
想点击listbox中的项时,将其值放到textbox中,再在textbox中修改后点击按钮,则更新listbox中选择项。请问c#代码怎么写。...
想点击 listbox中的项时,将其值放到textbox中,再在textbox中修改后点击按钮,则更新listbox中选择项。请问c#代码怎么写。
展开
3个回答
展开全部
给LISTBOX添加ONCLICK事件,在这个事件发生时,将这个LISTBOX的SELECTEDITEM的TEXT赋值给TEXTBOX的text,然后,点击这个修改按钮时,触发ONCLICK事件,将LISTBOX的值修改了,然后绑定
我来写代码,你等等,如果上面的思路够用了,那你自己写
<asp:ListBox ID="lbData" runat="server" onselectedindexchanged="lbData_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="111" Value="1"></asp:ListItem>
<asp:ListItem Text="222" Value="2"></asp:ListItem>
<asp:ListItem Text="333" Value="3"></asp:ListItem></asp:ListBox>
<asp:TextBox ID="txtChange" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Button" onclick="btnSubmit_Click" />
protected void lbData_SelectedIndexChanged(object sender, EventArgs e)
{
this.txtChange.Text= this.lbData.SelectedItem.Text;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
this.lbData.SelectedItem.Text = txtChange.Text;
}
我来写代码,你等等,如果上面的思路够用了,那你自己写
<asp:ListBox ID="lbData" runat="server" onselectedindexchanged="lbData_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="111" Value="1"></asp:ListItem>
<asp:ListItem Text="222" Value="2"></asp:ListItem>
<asp:ListItem Text="333" Value="3"></asp:ListItem></asp:ListBox>
<asp:TextBox ID="txtChange" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Button" onclick="btnSubmit_Click" />
protected void lbData_SelectedIndexChanged(object sender, EventArgs e)
{
this.txtChange.Text= this.lbData.SelectedItem.Text;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
this.lbData.SelectedItem.Text = txtChange.Text;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if(this.listBox1.SelectedIndex!=-1) //必要
this.textBox1.Text = this.listBox1.SelectedItem.ToString();
}
private void button4_Click(object sender, EventArgs e)
{
this.listBox1.Items[this.listBox1.SelectedIndex] = this.textBox1.Text;
}
{
if(this.listBox1.SelectedIndex!=-1) //必要
this.textBox1.Text = this.listBox1.SelectedItem.ToString();
}
private void button4_Click(object sender, EventArgs e)
{
this.listBox1.Items[this.listBox1.SelectedIndex] = this.textBox1.Text;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没有那么麻烦吧?
int i;
private void listBox1_Click(object sender, EventArgs e)
{
i = this.listBox1.SelectedIndex;
this.textBox1.Text = this.listBox1.SelectedItem.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
this.listBox1.Items[i] = this.textBox1.Text;
}
int i;
private void listBox1_Click(object sender, EventArgs e)
{
i = this.listBox1.SelectedIndex;
this.textBox1.Text = this.listBox1.SelectedItem.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
this.listBox1.Items[i] = this.textBox1.Text;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询