Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Have to click the edit button 2ce in datagrid. 2

Status
Not open for further replies.

qwert231

Programmer
Sep 4, 2001
756
US
I have put together a datagrid, it will only ever return one record, but the editCommandColumn edit button (in fact all the buttons) takes 2 clicks before a response happens. Any ideas why this happens?

2nd question, related... I have not been able to put an edit button in the item template. Any idease how to do this? (I just would like to avoid a second column.) So far this datagrid has been acting funny.

3rd question (this datagrid has been acting funny.) When I do get Edit to fire I simply do a postback with this command:
Code:
jobInfoDG.EditItemIndex = e.Item.ItemIndex
but the text from the second field (YBK) remains. How could I clear that out?

Code:
<asp:datagrid id=&quot;jobInfoDG&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;False&quot; ShowHeader=&quot;False&quot; onEditCommand=&quot;doEdit&quot; onCancelCommand=&quot;doCancel&quot; onUpdateCommand=&quot;doUpdate&quot;>
     <Columns>
      <asp:TemplateColumn>
       <ItemTemplate>
        <TABLE align=&quot;center&quot;>
         <TR>
          <TD><B>Subject ID:</B></TD>
          <TD><%# container.DataItem (&quot;SubjectID&quot;) %></TD>
         </TR>
         <TR>
          <TD><B>Style:</B></TD>
          <TD><%# container.DataItem (&quot;YBK&quot;) %></TD>
         </TR>
         <TR>
          <TD><B>Quantity:</B></TD>
          <TD><%# container.DataItem (&quot;YBQTY&quot;) %></TD>
         </TR>
        </TABLE>
       </ItemTemplate>
       <EditItemTemplate>
        <TABLE align=&quot;center&quot;>
         <TR>
          <TD><B>Image ID:</B></TD>
          <TD><%# container.DataItem (&quot;Name&quot;) %></TD>
         </TR>
         <TR>
          <TD><B>Style:</B></TD>
          <TD>
           <asp:DropDownList id=&quot;DropDownList1&quot; runat=&quot;server&quot;>
            <asp:ListItem Value=&quot;YBK&quot;>Color</asp:ListItem>
            <asp:ListItem Value=&quot;YBKBW&quot;>B&W</asp:ListItem>
            <asp:ListItem Value=&quot;YBK35&quot;>Custom Color</asp:ListItem>
            <asp:ListItem Value=&quot;YBK35BW&quot;>Custom B&W</asp:ListItem>
            <asp:ListItem Value=&quot;YBKS&quot;>Ybk Strip</asp:ListItem>
           </asp:DropDownList></TD>
         </TR>
         <TR>
          <TD><B>Quantity:</B></TD>
          <TD>
           <ASP:textbox id=&quot;Textbox3&quot; runat=&quot;server&quot; Width=&quot;50px&quot;></ASP:textbox></TD>
         </TR>
        </TABLE>
       </EditItemTemplate>
      </asp:TemplateColumn>
      <asp:EditCommandColumn ButtonType=&quot;PushButton&quot; UpdateText=&quot;Update&quot; CancelText=&quot;Cancel&quot; EditText=&quot;Edit&quot;></asp:EditCommandColumn>
     </Columns>
    </asp:datagrid>
 
Okay, 1st things 1st... I want a narrower datagrid. How do I move the position of the Edit button, and how do I Get Update and Cancel to go over each other instead of Next to each other?
 
Okay, I'm struggling through this. I realized you could change an EditCommandColumn into a TemplateColumn, and in so doing, the Buttons are created. Then you can move those buttons into any other TemplateColumn. Or, use them for a pattern, and learn how to create the buttons yourself.

HOWEVER, I am still having trouble, my Edit button takes 2 clicks on one form, and doesn't do anything on another. What gives.
 
Okay, here's the codebehind for my datagrid (1 of them) I have two that look the same, but felt it better to have on separate pages. I am looking for any help with my current problem of having to push any button 2 for an action.

Also, please critique my coding, let me know if there are any areas I can improve. Thanks
(No action for Update and Delete yet, when buttons fire correctly I will work on them.)

Code:
Public Class editYB
 Inherits System.Web.UI.Page

#Region &quot;Declarations&quot;

 Protected WithEvents newJob As System.Web.UI.WebControls.Label
 Protected WithEvents jobInfoDG As System.Web.UI.WebControls.DataGrid
 Protected WithEvents returnBtn As System.Web.UI.WebControls.LinkButton

#End Region

#Region &quot; Web Form Designer Generated Code &quot;

 'This call is required by the Web Form Designer.
 <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

 End Sub

 Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
  'CODEGEN: This method call is required by the Web Form Designer
  'Do not modify it using the code editor.
  InitializeComponent()
 End Sub

#End Region

#Region &quot;My Code&quot;

 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  If Not Page.IsPostBack Then
   BindData()
  End If
 End Sub

 Private Sub BindData()
  Dim jType As String
  Dim ybJob As String
  Dim nowJob As String
  Dim oldJob As String
  Dim subj As String
  ybJob = Request.QueryString(&quot;ybJob&quot;)
  subj = Request.QueryString(&quot;subj&quot;)
  newJob.Text = ybJob
  Dim strReq As String = &quot;SELECT SubjectID,YBK,YBQTY FROM tblOrderDetails WHERE yOrder LIKE '&quot; & ybJob & &quot;' AND SubjectID LIKE '&quot; & subj & &quot;'&quot;
  Dim objConn As New System.Data.OleDb.OleDbConnection(Application(&quot;dbAccess&quot;))
  Dim objComm As New System.Data.OleDb.OleDbCommand(strReq, objConn)
  Dim objReader As System.Data.OleDb.OleDbDataReader
  objConn.Open()
  Try
   objReader = objComm.ExecuteReader()
   jobInfoDG.DataSource = objReader
   jobInfoDG.DataBind()
  Catch excep As Exception
  Finally
   objReader.Close()
  End Try
  objConn.Close()
 End Sub

 Private Sub returnBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles returnBtn.Click
  Response.Redirect(&quot;senList.aspx&quot;) '?ybJob=&quot; & Request.QueryString(&quot;ybJob&quot;) & &quot;&nowJob=&quot; & Request.QueryString(&quot;nowJob&quot;) & &quot;&oldJob=&quot; & Request.QueryString(&quot;oldJob&quot;))
 End Sub

 Private Sub doEdit(ByVal sender As System.Object, ByVal e As DataGridCommandEventArgs) Handles jobInfoDG.EditCommand
  jobInfoDG.EditItemIndex = e.Item.ItemIndex
 End Sub

 Private Sub doCancel(ByVal sender As System.Object, ByVal e As DataGridCommandEventArgs) Handles jobInfoDG.CancelCommand
  jobInfoDG.EditItemIndex = -1
 End Sub

 Private Sub doUpdate(ByVal sender As System.Object, ByVal e As DataGridCommandEventArgs) Handles jobInfoDG.UpdateCommand
  jobInfoDG.EditItemIndex = -1
 End Sub

 Private Sub doDelete(ByVal sender As System.Object, ByVal e As DataGridCommandEventArgs) Handles jobInfoDG.DeleteCommand
  jobInfoDG.EditItemIndex = -1
 End Sub

#End Region

End Class

Here is the datagrid code:
Code:
<asp:datagrid id=&quot;jobInfoDG&quot; runat=&quot;server&quot; ShowHeader=&quot;False&quot; AutoGenerateColumns=&quot;False&quot; BorderStyle=&quot;None&quot; BorderWidth=&quot;0px&quot;>
     <Columns>
      <asp:TemplateColumn>
       <ItemTemplate>
        <U>Review</U>
        <TABLE align=&quot;center&quot; border=&quot;0&quot;>
         <TR>
          <TD><B>Image ID:</B></TD>
          <TD><%# container.DataItem (&quot;SubjectID&quot;) %></TD>
         </TR>
         <TR>
          <TD><B>Style:</B></TD>
          <TD><%# container.DataItem (&quot;YBK&quot;) %></TD>
         </TR>
         <TR>
          <TD><B>Quantity:</B></TD>
          <TD><%# container.DataItem (&quot;YBQTY&quot;) %></TD>
         </TR>
        </TABLE>
        <P align=&quot;center&quot;><asp:Button id=&quot;dgEdit&quot; runat=&quot;server&quot; CausesValidation=&quot;false&quot; CommandName=&quot;Edit&quot; Text=&quot;Edit&quot;></asp:Button> 
        <asp:Button id=&quot;dgDelete&quot; runat=&quot;server&quot; CausesValidation=&quot;false&quot; CommandName=&quot;Delete&quot; Text=&quot;Delete&quot;></asp:Button></P>
       </ItemTemplate>
       <EditItemTemplate>
        <U>Edit</U>
        <TABLE align=&quot;center&quot; border=&quot;0&quot;>
         <TR>
          <TD><B>Image ID:</B></TD>
          <TD><%# container.DataItem (&quot;Name&quot;) %></TD>
         </TR>
         <TR>
          <TD><B>Style:</B></TD>
          <TD>
           <asp:DropDownList id=&quot;DropDownList1&quot; runat=&quot;server&quot;>
            <asp:ListItem Value=&quot;YBK&quot;>Color</asp:ListItem>
            <asp:ListItem Value=&quot;YBKBW&quot;>B&W</asp:ListItem>
            <asp:ListItem Value=&quot;YBK35&quot;>Custom Color</asp:ListItem>
            <asp:ListItem Value=&quot;YBK35BW&quot;>Custom B&W</asp:ListItem>
            <asp:ListItem Value=&quot;YBKS&quot;>Ybk Strip</asp:ListItem>
           </asp:DropDownList></TD>
         </TR>
         <TR>
          <TD><B>Quantity:</B></TD>
          <TD>
           <ASP:textbox id=&quot;Textbox3&quot; runat=&quot;server&quot; Width=&quot;50px&quot;></ASP:textbox></TD>
         </TR>
        </TABLE>
        <P align=&quot;center&quot;>
         <asp:Button id=&quot;dgUpdate&quot; runat=&quot;server&quot; CommandName=&quot;Update&quot; Text=&quot;Update&quot;></asp:Button>
         <asp:Button id=&quot;dgCancel&quot; runat=&quot;server&quot; CausesValidation=&quot;false&quot; CommandName=&quot;Cancel&quot; Text=&quot;Cancel&quot;></asp:Button></P>
       </EditItemTemplate>
      </asp:TemplateColumn>
     </Columns>
    </asp:datagrid>
 
You're failing to call your bindData routine in the event handlers
penny1.gif
penny1.gif
 
Righto, thanks you guys again. Duh on me for that last one. hehe... It's good we can laugh at ourselves.

&quot;Yea, I knew that... I just forgot.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top