In the ItemCommand event find out which button was clicked by using the CommandArgument attr. This could then fire a switch to choose the correct method (SetupFormA, SetupFormB) for looping thru the GridView so you can find and changing the the form fields required. I haven't tired this myself but that's how I would go about it to start with.
JamieRushton_
Posts
-
Conditional Editing in Grid View -
Set label's text clientside and use it to set button's text server side.Only other way I can think of is to use a hidden field.
<!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>Test</title>
<script type="text/javascript">
function Hello() {
var value = "bye";document.getElementById("<%=Button2.ClientID %>").disabled = false; document.getElementById("<%=Label1.ClientID %>").innerText = value; document.getElementById("<%=hdnValue.ClientID %>").value = value; } </script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button" value="Button1" onclick="Hello()" /><br /><asp:Button ID="Button2" runat="server" Enabled="False" Text="Button2" /> <br /> <asp:Label runat="server" ID="Label1" Text="hello" /> <asp:HiddenField ID="hdnValue" runat="server" /> </div> </form>
</body>
</html>void Page_Init(object sender, EventArgs e)
{
Button2.Click += new EventHandler(Button2_Click);
}protected void Page_Load(object sender, EventArgs e)
{
}void Button2_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
button.Text = hdnValue.Value;
} -
Set label's text clientside and use it to set button's text server side.Oops sorry. Can you not simply use the code-behind to solve this issue? Because your clicking on a server control the page is reloaded back to its orginal state. If you want to change the text of the button after changing the label control using JavaScript then you will need to change the second button using JavaScript also.
-
Set label's text clientside and use it to set button's text server side.Markup - HTML
<!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>Test</title>
<script type="text/javascript">
function Hello()
{
document.getElementById('Button2').disabled = false;
document.getElementById('Label1').innerText = "bye";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button" value="Button1" onclick="Hello()" /><br /><asp:Button ID="Button2" runat="server" Enabled="False" Text="Button2" /><br /> <asp:Label runat="server" ID="Label1" Text="hello" /> </div> </form>
</body>
</html>Code-behind
void Page_Init(object sender, EventArgs e)
{
Button2.Click += new EventHandler(Button2_Click);
}protected void Page_Load(object sender, EventArgs e)
{}
void Button2_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
button.Text = "Something new";
} -
Front end & Back end -
Adding textbox column to gridview programmatically (vb.net)Use the GridViews DataBound event. C#
protected void Page_Init(object sender, EventArgs e)
{
GridView1.DataBound += new EventHandler(GridView1_DataBound);
}void GridView1_DataBound(object sender, EventArgs e)
{
GridView gridview = (GridView)sender;try { foreach (GridViewRow row in gridview.Rows) { TextBox textbox = new TextBox(); textbox.Text = "Something"; TableCell tableCell = new TableCell(); tableCell.Controls.Add(textbox); row.Cells.Add(tableCell); } } catch (Exception ex) { }
}
Private Sub GridView1_DataBound(sender As Object, e As EventArgs)
Dim gridview As GridView = CType(sender, GridView)
Try
For Each row As GridViewRow In gridview.Rows
Dim textbox As New TextBox()
textbox.Text = "Something"Dim tableCell As New TableCell() tableCell.Controls.Add(textbox) row.Cells.Add(tableCell) Next Catch ex As Exception End Try
End Sub