출처: http://www.ezzylearning.com/tutorial.aspx?tid=5066444

protected void GridView_List_RowCommand(object sender, GridViewCommandEventArgs e)
{
           
            string currentCommand = e.CommandName;
            int currentRowIndex = Int32.Parse(e.CommandArgument.ToString());
            string ProductID = GridView_List.DataKeys[currentRowIndex].Value;

            Label1.Text = "Command: " + currentCommand;
            Label2.Text = "Row Index: " + currentRowIndex.ToString;
            Label3.Text = "Product ID: " + ProductID;   

}


 


<asp:ButtonField ButtonType="link" CommandName="ProductName" 
         DataTextField="ProductName" HeaderText="Name"
         SortExpression="ProductName" />



Posted by 노을지기

간단한 방법이 있었는데.. 이것을 못 찾고 있었다.ㅡㅡ;;

출처: http://stackoverflow.com/questions/17311757/on-clicking-the-hyperlink-inside-gridview-it-should-redirect-to-a-page-and-and

<asp:HyperLink ID="hlView" runat="server" Text="View" NavigateUrl='<%# "~/pageredirect.aspx?id=" + Eval("Id") %>'></asp:HyperLink>

 

변형

<Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:HyperLink ID="HyperLink_Edit" runat="server" NavigateUrl='<%# "./CustomerTemplateDetail.aspx?code=" + Eval("NO") %>' Text="Edit"></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>

</Columns>



Posted by 노을지기

출처: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.detailsview.itemupdating%28v=vs.110%29.aspx

가끔 데이터 입력시 확인이 필요하거나 자동으로 입력이 필요할 때가 있다.

이때 필요한 것들

void CustomerDetail_ItemInserting(object sender, 
    DetailsViewInsertEventArgs e)
  {
    // Iterate though the values entered by the user and HTML encode 
    // the values. This helps prevent malicious values from being 
    // stored in the data source.
    for (int i = 0; i < e.Values.Count; i++)
    {
      if (e.Values[i] != null)
      {
        e.Values[i] = Server.HtmlEncode(e.Values[i].ToString());
      }
    }
  }


Posted by 노을지기

버튼으로 DetailsView의 모드를 변경할 경우가 있다.

이때 모드 확인 후 사용하기

// check the Detail View Mode
 if (DetailsView1.CurrentMode == DetailsViewMode.Insert)
{
      DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
 } 

 mode는 3가지가 있다.

edit, insert, readonly


Posted by 노을지기

출처: http://brian.chipsofttech.com/post/DetailsView-Confirm-Delete.aspx

itemCreated 이벤트에서 사용하면 된다.

protected void DetailsView1_ItemCreated(object sender, EventArgs e)
        {
            // Test FooterRow to make sure all rows have been created
            if (DetailsView1.FooterRow != null)
            {
                // The command bar is the last element in the Rows collection
                int commandRowIndex = DetailsView1.Rows.Count - 1;
                if (commandRowIndex > 0)
                {
                    DetailsViewRow commandRow = DetailsView1.Rows[commandRowIndex];
                    // Look for the DELETE button
                    DataControlFieldCell cell = (DataControlFieldCell)commandRow.Controls[0];
                    foreach (Control ctl in cell.Controls)
                    {
                        LinkButton link = ctl as LinkButton;
                        if (link != null)
                        {
                            if (link.CommandName == "Delete")
                            {
                                link.ToolTip = "Click here to delete";
                                link.OnClientClick = "return confirm('Do you really want to delete this record?');";
                            }
                        }
                    }
                }
            }
        }

Posted by 노을지기